How to rename an associative array in Bash?

后端 未结 8 2140
感情败类
感情败类 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
    

提交回复
热议问题