Question

Let's say I have the following code:

#!/bin/bash

arrayName_1=( 3 4 5 )
arrayName_2=( 0 1 2 )
str="arrayName_1"
arrayName=?

In the end, I want arrayName variable to be an array containing 3, 4, 5, just like arrayName_1. How do I make this happen? I know I could do the below, but I have to use str instead of arrayName_1:

arrayName=("${arrayName_1[@]}")
Était-ce utile?

La solution

Try this:

arrayName_1=( 3 4 5 )
arrayName_2=( 0 1 2 )
name="arrayName_1"
indirect=$name"[@]"
arrayName=("${!indirect}")
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top