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
Post a Comment