数组的定义:
方法1:
array=(1 2 3)
echo ${array[*]} //输出数组里的所有元素
结果:1 2 3
方法2:
array=([1]=one [2]=two [3]=three) //数组的下标对应元素,前面还有个下标为0
echo ${array[*]}
结果:one two three
echo ${array[1]}
结果: one
方法3:数组元素的改变,重新赋值
array[0]=a
array[1]=b
array[2]=c
echo ${array[1]}
结果:a b c three
方法4:
统计数组元素:
array=(one two three)
echo ${array[*]}
结果:one two three
echo ${array[@]}
结果:one two three
统计数组元素的个数:
echo ${#array[*]}
结果:3
echo ${#array[@]}
结果:3
给数组赋值:
array[3]=four
echo ${array[*]}
one two three four
数组的删除:
数组内容截取和替换
数组中元素的替换: