1 #!/bin/bash 2 # 数组 3 4 # 数组的定义 5 a=(0 1 2 3) 6 # 数组元素的访问 7 echo "a[0]:${a[0]}" 8 # 数组的长度 9 echo "length:${#a[*]}"10 # 所有元素11 echo "all element:${a[*]}"12 # 删除某个元素13 unset a[1]14 echo "after unset:${a[*]}"15 16 echo "用for in 遍历"17 for every in ${a[*]}18 do19echo "every:$every"20 done21 22 23 echo "用for(())遍历"24 for ((i=0;i<=5;i++))25 do26array[$i]=027 done28 29 for ((i=0;i<${#array[*]};i++))30 do31echo ${array[$i]}32 done
输出:
a[0]:0
length:4
all element:0 1 2 3
after unset:0 2 3
用for in 遍历
every:0
every:2
every:3
用for(())遍历
0
0
0
0
0
0