I faced with a very strange behavior.
#!/bin/bash
declare -A array_first=(
[name]="Array 1"
[message]="Hi there"
)
declare -A array_second=(
[name]="Array 2"
[message]="Bye!"
)
arrays=(array_first array_second)
for arr in ${!arrays[*]}
do
val=${arrays[$arr]}
val=${!val}
echo ${val[name]} # Why this string is empty?
done
echo "${array_first[name]}"
echo "${array_first[message]}"
echo "${array_second[name]}"
echo "${array_second[message]}"
I need the value of an associative array, and displays an empty string. What am I doing wrong?