Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 23 Dec 2000 21:31:05 +0200
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Aaron Hill <hillaa@hotmail.com>
Cc:        davidd@datasphereweb.com, questions@FreeBSD.ORG
Subject:   Re: Script: Variable substition within a variable?
Message-ID:  <20001223213105.C48060@hades.hell.gr>
In-Reply-To: <F157QBRbpOmK1iY1VBn00000efe@hotmail.com>; from hillaa@hotmail.com on Mon, Dec 18, 2000 at 04:10:36AM %2B0000
References:  <F157QBRbpOmK1iY1VBn00000efe@hotmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20001223213105.C48060>