How to copy an array in Bash?

后端 未结 8 1931
陌清茗
陌清茗 2020-12-02 15:31

I have an array of applications, initialized like this:

depends=$(cat ~/Depends.txt)

When I try to parse the list and copy it to a new arra

8条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 15:41

    The simplest way to copy a non-associative array in bash is to:

    arrayClone=("${oldArray[@]}")

    or to add elements to a preexistent array:

    someArray+=("${oldArray[@]}")

    Newlines/spaces/IFS in the elements will be preserved.

    For copying associative arrays, Isaac's solutions work great.

提交回复
热议问题