Reputation: 3378
Let's say, I have 3 variables, A=1
, B=2
, C=3
and finally a last variable containing the name of either of them (VAR=A
). Is it possible to call A, B, C based on VAR's content without 'if's?
Like echo "${$VAR}"
?
Upvotes: 2
Views: 77
Reputation: 47762
Yes.
eval echo \$$VAR
There is also a bash-only way of doing this, using indirect reference:
echo ${!VAR}
Upvotes: 3