Im no bash/shell script expert...what im trying to do the is following: im using array variables as keys to a hashmap. when i iterate over the keys of the hash map i want to evaluate them to the actual array, iterate over the array and print the values in that array out.
arr1=(A B)
arr2=(C D)
declare -A arrmap
arrmap=(
[arr1]="array 1"
[arr2]="array 2"
)
for k in "${!arrmap[@]}";
do
for f in "${k[@]}";
do echo "$k: $f";
done
done
This prints out:
arr2: arr2
arr1: arr1
but what i would like to see is:
A: array 1
B: array 1
C: array 2
D: array 2
EDIT: think i was able to figure it out:
for k in "${!arrmap[@]}"; do
eval a=\( \${${k}[@]} \)
for f in "${a[@]}"; do
echo "$k: $f";
done
done