In bash, if I have:
y=10
x='y'
echo $x # prints 'y'
Now I want to get $y via $x:
echo ${$x} # error: "bad substitution"; I want to print 10
How do I lookup the variable value with name $x?
In bash, if I have:
y=10
x='y'
echo $x # prints 'y'
Now I want to get $y via $x:
echo ${$x} # error: "bad substitution"; I want to print 10
How do I lookup the variable value with name $x?
Use eval for indirect references while escaping the outer dollar sign
eval echo "\${$x}"
To assign to a variable
eval "z=\${$x}"
echo "$z"
# 10