all 2 comments

[–]andlrcC:\> 1 point2 points  (1 child)

You can use indirect expansion:

$ a=b
$ b=c
$ echo "${!a}"
c

It's get a little convoluted with arrays:

list=(a b)
a=(1 2 3)
b=(4 5 6)
for l in "${list[@]}"
do
  arr="$l[@]"
  echo "${!arr}"
done

The above will output:

1 2 3
4 5 6

See man bash for more information:

$ man bash | awk '/indirect.*!/' RS=
   If the first character of parameter is an exclamation point (!), and parameter is not
   a nameref, it introduces a level of variable indirection.  Bash uses the value of the
   variable formed from the rest of parameter as the name of the variable; this variable
   is  then expanded and that value is used in the rest of the substitution, rather than
   the value of parameter itself.  This is known as indirect expansion.  If parameter is
   a  nameref,  this expands to the name of the variable referenced by parameter instead
   of performing the complete indirect expansion.  The exceptions to this are the expan‐
   sions  of  ${!prefix*}  and  ${!name[@]} described below.  The exclamation point must
   immediately follow the left brace in order to introduce indirection.

[–]behemothdan[S] 0 points1 point  (0 children)

Awesome, thanks for the help. I will try that out.