How to format and move an array containing arrays and each array contains an array?

I am trying to create multi-dimensional inside arrays that are contained in an array.

tests=("'0' '1 2'" "'4' '5 6'") 

in every array in tests, I want to have helper arrays. With the first array '' 0 '' 1,2 '', do another loop to view the contents of the auxiliary array.

0
bash shell
Jun 29 '17 at 15:11
source share
1 answer

Since bash 4.3. (3 levels, the first contains only one element for demonstration):

 arr01=(0 '1 2') arr02=(4 '5 6') arr1=(arr01 arr02) arr=(arr1) declare -n elmv1 elmv2 for elmv1 in "${arr[@]}"; do for elmv2 in "${elmv1[@]}"; do for elm in "${elmv2[@]}"; do echo "<$elm>" done done done 

Up to 4.3

 arr01=(0 '1 2') arr02=(4 '5 6') arr1=('arr01[@]' 'arr02[@]') arr=('arr1[@]') for elmv1 in "${arr[@]}"; do for elmv2 in "${!elmv1}"; do for elm in "${!elmv2}"; do echo "<$elm>" done done done 
+1
Jun 29 '17 at 17:05
source share



All Articles