I am trying to expand all values in an array I get to through indirect expansion:
> my_array=(coconut banana)
> echo "${my_array[@]}"
coconut banana
> my_array_name=my_array
> echo ${!my_array_name}
coconut
> echo "${!my_array_name[@]}"
0
I am erroneously using "List of array keys" in the last command because I don't know how to type the right command?
I would like to get:
coconut banana
possibly without resorting to some ugly eval hack.. Example of one suck hack:
> echo \${$my_array_name[@]}
${my_array[@]}
> eval echo \${$my_array_name[@]}
coconut banana
Note
my_array may contain values with spaces!
EDIT
In the function I am writing, my_array_name is set through "$1" so I cannot use that literally.
Similar to: https://unix.stackexchange.com/questions/20171/indirect-return-of-all-elements-in-an-array but I need to avoid using eval to protect from the nasty effects the script would have if the environment was "hacked" just at the right time...