#空数组
n1=()
#n1 is ()
#元素用空格分隔,而不是用逗号:
#(1, 2, 3) 会得到元素 "1,"、"2," 和 "3"
n2=(1 2 3)
n3=("one" "two" "three")
#n3[2] is "three"
#按索引赋值:它们之间的索引不存在
n4=([1]=10 [3]=30)
#n4 is (10 30), its indexes are (1 3)
#由范围和由命令输出的各行创建的数组
n5=({1..5})
#n5 is (1 2 3 4 5)
mapfile -t n6 < <(seq 3 -1 1)
#n6 is (3 2 1)
#bash 没有多维数组:
#用键为 "row,column" 的关联数组来代替
declare -A matrix=([0,0]=1 [0,1]=2 [1,0]=4 [1,1]=5)
#matrix[1,1] is 5
echo "n1 is (${n1[*]})"
echo "n2 is (${n2[*]})"
echo "n3[2] is ${n3[2]}"
echo "n4 is (${n4[*]}), its indexes are (${!n4[*]})"
echo "n5 is (${n5[*]})"
echo "n6 is (${n6[*]})"
echo "matrix[1,1] is ${matrix[1,1]}"