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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -