How to get the keys and values of an associative array indirectly in Bash?
问题 In Bash, given only a variable that contains the name of an associative array, $ declare -A dict=([abc]=125 [def]=456) $ dictvar="dict" how can we retrieve the keys and values of the associative array? 回答1: In Bash, to get keys of an associative array via indirection, given the name of the array in variable dictvar one can leverage declare or local (original source): $ declare -a 'keys=("${!'"$dictvar"'[@]}")' # or 'local' Then, to get the values $ for key in ${keys[@]}; do $ value_var="$