1.定义数组
1
#array=(1 2 3 4)
2.计算数组的个数
1
2
#echo ${#array[@]}
3
3.打印数组
1
2
3
4
#echo ${array[0]}
1
#echo ${array[1]}
2
(这里数组是从0开始,0代表第一个元素)
4.打印整个数组
1
2
3
4
#echo ${array[*]}
1 2 3
#echo ${array[@]}
1 2 3
5.数组的赋值
1
2
3
# array[0]=xiaolangit
# echo ${array[@]}
xiaolangit 2 3 4
6.删除单个数组
1
2
3
#array=(1 2 3)
#unset array[0]
#echo ${array[@]}
7.截取
输出数组第1个到第3个值
1
2
3
#array=(1 2 3 4 5)
#echo ${array[@]:1:3}
2 3 4
输出数组除了第1个值
1
2
#echo ${array[@]:1}
#2 3 4 5
8.替换
1
2
#echo ${array[@]/5/6}
1 2 3 4 6
9.匹配
1
2
3
4
5
#array=(one two three four five)
#echo ${array[@]#o}
ne two three four five
#echo ${array[@]#fo}
one two three ur five
阅读(1323) | 评论(0) | 转发(0) |