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

java - How to pass parameters between Request-Scoped Controllers? -

actionscript 3 - Flex: moving a point with rotation doesnt change the point XY? -

ms access - C# - Using OleDbParameter on table name -