shell数组
创建静态数组
[root@VM-16-13-centos learn]# array=(1 2 3)
创建动态数组
[root@VM-16-13-centos learn]# array=(`ls`)
查看数组
[root@VM-16-13-centos learn]# echo ${array[*]}
查看数组长度
[root@VM-16-13-centos learn]# echo ${#array[*]}
查看数组的第一个值
[root@VM-16-13-centos learn]# echo ${array[0]}
数组追加
[root@VM-16-13-centos learn]# array[3]=4
数组删除
[root@VM-16-13-centos learn]# unset array[3]
数组截取
[root@VM-16-13-centos learn]# echo ${array[*]:1:2}
创建动态数组
[root@VM-16-13-centos learn]# array=(`ls`)
查看数组
[root@VM-16-13-centos learn]# echo ${array[*]}
for循环打印数组
[root@VM-16-13-centos learn]# cat arr.sh
arr=(
`ls`
)
for i in ${arr[*]}
do
echo $i
done

浙公网安备 33010602011771号