I am trying to do something like below:
for a in apple orange grape; do
${!a}="blah"
done
echo $apple
blah
Possible?
Use declare
.
for a in apple orange grape; do
declare "$a=blah"
done
I wonder if you might want to use associative arrays instead:
declare -A myarray
for a in apple orange grape; do
myarray[$a]="blah"
done
echo ${myarray[apple]}
Note associative arrays require bash version 4.0 or greater.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With