How to rename an associative array in Bash?

后端 未结 8 2108
感情败类
感情败类 2020-12-08 21:51

I need to loop over an associative array and drain the contents of it to a temp array (and perform some update to the value).

The leftover contents of the first arra

相关标签:
8条回答
  • 2020-12-08 22:53

    With associative arrays, I don't believe there's any other method than iterating

    for key in "${!TEMPARRAY[@]}"  # make sure you include the quotes there
    do
      MAINARRAY["$key"]="${TEMPARRAY["$key"]}"
      # or: MAINARRAY+=( ["$key"]="${TEMPARRAY["$key"]}" )
    done
    
    0 讨论(0)
  • 2020-12-08 22:53
    MAINARRAY=( "${TEMPARRAY[@]}" )
    
    0 讨论(0)
提交回复
热议问题