From owner-freebsd-hackers Fri Jan 27 11:33:08 1995 Return-Path: hackers-owner Received: (from root@localhost) by freefall.cdrom.com (8.6.9/8.6.6) id LAA25471 for hackers-outgoing; Fri, 27 Jan 1995 11:33:08 -0800 Received: from ibp.ibp.fr (ibp.ibp.fr [132.227.60.30]) by freefall.cdrom.com (8.6.9/8.6.6) with ESMTP id LAA25461 for ; Fri, 27 Jan 1995 11:33:01 -0800 Received: from blaise.ibp.fr (blaise.ibp.fr [132.227.60.1]) by ibp.ibp.fr (8.6.8/jtpda-5.0) with SMTP id UAA07246 ; Fri, 27 Jan 1995 20:34:15 +0100 Received: by blaise.ibp.fr (4.1/SMI-4.1) id AA17198; Fri, 27 Jan 95 20:34:11 +0100 From: roberto@blaise.ibp.fr (Ollivier ROBERT) Message-Id: <9501271934.AA17198@blaise.ibp.fr> Subject: Re: shell trick? To: dgy@seagull.rtd.com (Don Yuniskis) Date: Fri, 27 Jan 1995 20:34:11 +0100 (MET) Cc: freebsd-hackers@freefall.cdrom.com In-Reply-To: <199501271814.LAA21622@seagull.rtd.com> from "Don Yuniskis" at Jan 27, 95 11:14:06 am X-Operating-System: FreeBSD 2.1.0-Development ctm#307 X-Mailer: ELM [version 2.4 PL23beta2] Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Content-Length: 1100 Sender: hackers-owner@FreeBSD.org Precedence: bulk > 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_ with that : sub read_config_file { open (CONFIG, "$config") || die "Can't open $config.\n"; LOOP: while () { 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