1.定义数组

#array=(1 2 3 4)


2.计算数组的个数

#echo ${#array[@]}
3


3.打印数组

#echo ${array[0]}
1
#echo ${array[1]}
2

(这里数组是从0开始,0代表第一个元素)


4.打印整个数组

#echo ${array[*]}
1 2 3
#echo ${array[@]}
1 2 3


5.数组的赋值

# array[0]=xiaolangit
# echo ${array[@]}
xiaolangit 2 3 4


6.删除单个数组

#array=(1 2 3)
#unset array[0]
#echo ${array[@]}


7.截取

   输出数组第1个到第3个值

#array=(1 2 3 4 5)
#echo ${array[@]:1:3}
2 3 4


   输出数组除了第1个值

#echo ${array[@]:1}
#2 3 4 5


8.替换

#echo ${array[@]/5/6}
1 2 3 4 6


9.匹配

#array=(one two three four five)
#echo ${array[@]#o}
ne two three four five
#echo ${array[@]#fo}
one two three ur five