Date: Fri, 27 Jan 1995 20:34:11 +0100 (MET) From: roberto@blaise.ibp.fr (Ollivier ROBERT) To: dgy@seagull.rtd.com (Don Yuniskis) Cc: freebsd-hackers@freefall.cdrom.com Subject: Re: shell trick? Message-ID: <9501271934.AA17198@blaise.ibp.fr> In-Reply-To: <199501271814.LAA21622@seagull.rtd.com> from "Don Yuniskis" at Jan 27, 95 11:14:06 am
next in thread | previous in thread | raw e-mail | index | archive | help
> How can I, in a shell script, read lines from a file, expand any > environment variables referenced therein and write results to another > file? This not a real answer but you should really do this kind of things in perl... Its build-in eval function is great for this. You can create variables on the fly with new names, and so on. For example I read my new account configuration file and create variables named $conf_<something> with that : sub read_config_file { open (CONFIG, "$config") || die "Can't open $config.\n"; LOOP: while (<CONFIG>) { next if (/^#/o); # ignore comments next if (/^$/o); # ignore blank lines next if (/^[ \t]*$/o); # ignore lines with blanks and/or tabs chop; m#^([a-z0-9_]*)\s*=\s*(.+)$#; eval "\$conf_$1 = \"$2\";"; } } if the configuration file has : def_shell = /bin/tcsh then $conf_def_shell will have "/bin/tcsh" as value. Neat. -- Ollivier ROBERT -=- The daemon is FREE! -=- roberto@FreeBSD.ORG FreeBSD keltia 2.1.0-Development #18: Thu Jan 26 22:22:16 MET 1995
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9501271934.AA17198>