I'd like to know how to print variable value when I know the name of variable. I need a little help to put all the pieces together.
Let say I have a=A and b=B. Additionally I have list of a and b in file. And I want to print
a=A
b=B
I was testing with eval
, but I wasn't not able to do it in a for loop. I guess because I'm not able to capture the result of eval
...
which I can put together like this, but it smells...
setup
$ cat f.txt
a
b
$ a=A
$ b=B
execution
for n in `cat f.txt`
do
echo -n $n
eval echo \$$n
done
and wanted result is
a=A
b=B
but if I need to use the values later it won't work...
What I'm not able to do is
val=`eval echo \$$n`
to be able to do echo $val
later.