Assign array to variable

前端 未结 2 1202
一生所求
一生所求 2021-02-05 01:02

The issue about assigning arrays to variables in bash script seems rather complicated:

a=(\"a\" \"b\" \"c\")
b=$a

echo ${a[0]} 
echo ${a[1]}

echo ${b[0]} 
echo         


        
2条回答
  •  一整个雨季
    2021-02-05 01:26

    If you want to copy a variable that holds an array to another name, you do it like this:

    a=('a' 'b' 'c')
    b=( "${a[@]}" )
    

提交回复
热议问题