Just want to add some more points as well. Using eval or ! is not bad in all forms. Sometimes there's no choice other than use them like when emulating multi-dimentional arrays.
We know that this is not possible:
Code:
a[0][1]=2
echo ${a[0][1]}
so sometimes we have to do things like this:
Code:
a=(a0 a1 a2 a3 a4)
a0[1]=2
eval echo \${${a[0]}}
we probably can make a cleaner version to that with associative arrays like
Code:
a["0,1"]=2
echo ${a["0,1"]}
i=0 j=1
echo ${a["$i,$j"]} # correct me if the syntax of the index is incorrect.
but we know in associative arrays, we cannot associate many values as once as in indexed arrays and order of indices in associative arrays is never a guarantee. I'm not sure if it's sorted by default in bash.
Code:
a0=(value1 value2 value3 value4)
bvalues=<input from somewhere with values: value5 value6 value7 value8 in order>
b0=(${bvalues})
for A in ${a0[@]}; do ...
There are also many other situations where only indexed arrays can be applicable.