Suppose:
a=b; b=c; c=d
Then eval echo \$$a
produces the output:
c
If we want to extract the output d
using just input a
, I tried the following way:
(i) eval echo \$(eval echo \$$a)
produces the error:
syntax error near unexpected token '('
(ii) eval echo \$\(eval echo \$$a\)
produces the output:
c
I am not able to understand why escape slashing the bracket got rid of the error.
Also, could someone please explain why I didn't get the output as d
in the second instance?
eval
in any shell script unless you know exactly what you're doing. (And even then, there are virtually zero instances where it is actually the best solution.) As a beginner to shell scripting, please just forget thateval
even exists. :) – Wildcard yesterday