I have an array
declare -a arr0=("'1 2 3'" "'4 5 6'")
and a variable
x=0
Then I create the new variable with the array's name
tmp="arr$x"
and I'd like to be able to expand
arr0
content from this tmp
variable like this
newArr=( "${!tmp}" )
and to use newArr
like the ordinary array, e.g. use indices etc.
---
But when I try print it now, it looks like this:
$ echo ${newArr[@]}
'1 2 3'
Only the first element is stored and I don't know, how to fix it.
I've also tried to create newArr
like this
newArr=( "${!tmp[@]}" )
but then it's even worse - only 0 is printed.
$ echo ${newArr[@]}
0
---
So, do you know, how to use an array if its name is stored in some other variable?
Asked by Eenoku
(1245 rep)
Mar 8, 2017, 11:44 AM
Last activity: Jan 3, 2025, 07:16 AM
Last activity: Jan 3, 2025, 07:16 AM