From owner-freebsd-questions Sat Dec 23 16:51:56 2000 From owner-freebsd-questions@FreeBSD.ORG Sat Dec 23 16:51:51 2000 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from athserv.otenet.gr (athserv.otenet.gr [195.170.0.1]) by hub.freebsd.org (Postfix) with ESMTP id 8A9B237B404 for ; Sat, 23 Dec 2000 16:51:46 -0800 (PST) Received: from hades.hell.gr (patr530-b030.otenet.gr [195.167.121.158]) by athserv.otenet.gr (8.10.1/8.10.1) with ESMTP id eBO0pah16303; Sun, 24 Dec 2000 02:51:36 +0200 (EET) Received: (from charon@localhost) by hades.hell.gr (8.11.1/8.11.1) id eBNJV5Y70880; Sat, 23 Dec 2000 21:31:05 +0200 (EET) Date: Sat, 23 Dec 2000 21:31:05 +0200 From: Giorgos Keramidas To: Aaron Hill Cc: davidd@datasphereweb.com, questions@FreeBSD.ORG Subject: Re: Script: Variable substition within a variable? Message-ID: <20001223213105.C48060@hades.hell.gr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.4i In-Reply-To: ; from hillaa@hotmail.com on Mon, Dec 18, 2000 at 04:10:36AM +0000 X-PGP-Fingerprint: 3A 75 52 EB F1 58 56 0D - C5 B8 21 B6 1B 5E 4A C2 X-URL: http://students.ceid.upatras.gr/~keramida/index.html Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Mon, Dec 18, 2000 at 04:10:36AM +0000, Aaron Hill wrote: > Thanks for your prompt reply. > > >I think what you're looking for is something along the lines of: > >echo "Your name is " $fileone > > > I'm afraid that doesn't work. It seems that variable substitution only works > to one level - maybe this is for the best too. You can evaluate expressions once more with `eval'. If I understood the question correctly, you have the name of a variable in $name as in: $ name=datavar Then you need to get the contents of that file in $fileone variable: $ cat datafile piou $ datavar=`cat datafile` $ echo $datavar piou And you need to use $name as the name of a variable, which will then be echoed by your script: $ echo \$$name $datavar But you need this last expression, i.e. `$datavar', including the dollar sign to be evaluated: $ eval echo \$$name piou The first dollar sign is escaped by the backslash, and what `eval' finally evaluates is a dollar sign followed by `datafile', the value of $name. I hope that this helps a bit. - giorgos To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message