Bash indirect reference to an associative array -


in simplified example, need address both key , value of array element:

declare -a writer writer[h.p.]=lovecraft writer[stephen]=king writer[clive]=barker writer[jack]=ketchum  in ${!writer[@]}     echo "$i ${writer[$i]}" done  fullname() {     pointer=$1[@]     in "${!pointer}"             echo "? $i"     done } fullname writer 

the function must display output in same format example loop before it, , should receive either array name, list of keys or values, of tried, without success. suggestions appreciated.

indir_keys() {     eval "echo \${!$1[@]}" }  indir_val() {     eval "echo \${$1[$2]}" }  fullname() {     pointer=$1     in $(indir_keys $pointer)               echo "$i $(indir_val $pointer $i)"     done } 

gives:

jack ketchum clive barker stephen king h.p. lovecraft 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -