suppose in my script i have written
a1=2
a2=4
read option
# I directly want to see the value of a1 or a2 (i:e; 1 or2 )depending upon i/p given like a1 or a2 to option var.so what should i give .Suppose if I give a1 to option then how can I see the value.
echo $$option --- doesn't work
pls suggest
$$ is the pid. If you need two passes of variable expansion, use eval:
$ a1=A a2=B x=1
$ eval echo '$'a$x
A
$
First natural ksh pass removes ', treats $ as literal, a as literal, expands $x, giving "echo $a1"
Second, eval pass expands generated $a1 and runs echo (built in but identical to /bin/echo).
Also can be done as follows:
$ eval echo \$a$x
A
Yes, anything to stabilize the first $ on the first pass:
$ eval echo $\a$x
A
$ eval echo $"a$x"
A
$ eval echo $''a$x
A
$