shell - read array name from STDIN and iterating through the array values -


i have number of arrays want iterate through 1 entered through stdin code looks like

arr1=(a b c) arr2=(d e f) arr3=(g h i)  read array_name  in ${array_name[@]} echo "i $i" done 

now if enter arr1 input, arr1 values not printing. can please help

you can write:

arr1=(a b c) arr2=(d e f) arr3=(g h i)  read array_name  array_name="${array_name}[@]"    # append '[@]' array_name  in "${!array_name}" ;   # use indirection expand e.g. "${arr1[@]}"     echo "i $i" done 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -