()
指定元素給陣列變數 arr。
[dywang@dywmac zzz]$ unset arr [dywang@dywmac zzz]$ arr=(A B C)
${arr[@]}
取出陣列所有元素。
[dywang@dywmac zzz]$ echo ${arr[@]} A B C
${#arr[@]}
取出陣列 arr 的元素個數。
[dywang@dywmac zzz]$ echo ${#arr[@]} 3
[dywang@dywmac zzz]$ arr=(A B C) [dywang@dywmac zzz]$ arr[2]=R [dywang@dywmac zzz]$ echo ${arr[@]} A B R
[dywang@dywmac zzz]$ arr[3]=D [dywang@dywmac zzz]$ echo ${arr[@]} A B R D
[dywang@dywmac zzz]$ arr[6]=Y [dywang@dywmac zzz]$ echo ${arr[@]} A B R D Y [dywang@dywmac zzz]$ echo ${#arr[@]} 5 [dywang@dywmac zzz]$ echo ${arr[4]} [dywang@dywmac zzz]$ echo ${arr[6]} Y
[dywang@dywIssd zzz]$ arr=(1 12 13 14) [dywang@dywIssd zzz]$ arr1=(${arr[@]} 15) [dywang@dywIssd zzz]$ echo ${arr1[@]} 1 12 13 14 15
[dywang@dywIssd zzz]$ arr=(1 12 13 14) [dywang@dywIssd zzz]$ arr1=(0 ${arr[@]}) [dywang@dywIssd zzz]$ echo ${arr1[@]} 0 1 12 13 14
arr1=(${arr[@]:N-1:M})
[dywang@dywIssd zzz]$ arr=(1 12 13 14 15 16 17) [dywang@dywIssd zzz]$ arr1=(${arr[@]:2:5}) [dywang@dywIssd zzz]$ echo ${arr1[@]} 13 14 15 16 17
[dywang@dywIssd zzz]$ arr=(1 12 13 14 15 16 17) [dywang@dywIssd zzz]$ arr1=(${arr[@]:3}) [dywang@dywIssd zzz]$ echo ${arr1[@]} 14 15 16 17
[dywang@dywIssd zzz]$ arr=(1 12 13 14 15 16 17) [dywang@dywIssd zzz]$ arr1=(${arr[@]:0:$((${#arr[@]}-1))}) [dywang@dywIssd zzz]$ echo ${arr1[@]} 1 12 13 14 15 16