linux - Bash: How to assign an associative array to another variable name (e.g. rename the variable)? -



linux - Bash: How to assign an associative array to another variable name (e.g. rename the variable)? -

i need loop on associative array , drain contents of temp array (and perform update value).

the leftover contents of first array should discarded , want assign temp array original array variable.

sudo code:

declare -a mainarray declare -a temparray ... populate ${mainarray[...]} ... while something; #drain values mainarray temparray ${temparray["$name"]}=((${mainarray["$name"]} + $somevalue)) done ... other manipulations temparray ... unset mainarray #discard left on values had no update declare -a mainarray mainarray=${temparray[@]} #assign updated temparray mainarray (error here)

with associative arrays, don't believe there's other method iterating

for key in "${!temparray[@]}" # create sure include quotes there mainarray["$key"]="${temparray["$key"]}" # or: mainarray+=( ["$key"]="${temparray["$key"]}" ) done

linux bash variables associative-array

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -