First, sorry if I am cross-posting this question. I am not sure to
understand the difference between the 2 newsgroups.
My problem is that I have a shell variable containing a string
composed of variable names preceded with the expension operator ('$')
and I am fighting with the shell to find a way to make the expension.
Here is an example:
var1='$HOME'
echo $var1
will display $HOME but I would like to find a construction that would
allow me to print the $HOME value from the var1 variable.
Thank you for your assistance,
Olivier Langlois
http://www.olivierlanglois.net
http://blog.olivierlanglois.net
> Hi,
>
> First, sorry if I am cross-posting this question. I am not sure to
> understand the difference between the 2 newsgroups.
>
> My problem is that I have a shell variable containing a string
> composed of variable names preceded with the expension operator ('$')
> and I am fighting with the shell to find a way to make the expension.
> Here is an example:
>
> var1='$HOME'
> echo $var1
>
> will display $HOME but I would like to find a construction that would
> allow me to print the $HOME value from the var1 variable.
eval echo $var1
works for me
Ralf
Don't enclose the variable with quotes. For example:
HOME="Some Random Text"
TEST=$HOME
echo $TEST
This would then print the text "Some Random Text" without quotes which
is what you want ?
Glenn
I'd use Ralf's suggestion.
HOME="Other Random Text"
echo $TEST
Unaware of the existence of alt.comp.lang.shell.unix.bourne-bash,
I am grateful to you for exposing me to it. (Or it to me, rather.)
> My problem is that I have a shell variable containing a string
> composed of variable names preceded with the expension operator ('$')
> and I am fighting with the shell to find a way to make the expension.
eval is your friend:
$ FOO="foo's text"
$ BAR='$FOO'
$ echo $BAR
$FOO
$ eval echo $BAR
foo's text
(Perhaps I should have used a character other than '$' for my
prompt...)