Indirectly expand variables in shell
If you have var1=foo
and foo=bar
, you can get bar
by saying ${!var1}
. However, if you want to iterate over the positional parameters, it's almost certainly better to do
for i in "$@"; do
# something
done
Using /bin/bash
:
foo=bar
test=foo
echo ${!test}
# prints -> bar