每天一个shell知识--数组

时间:2023-03-08 21:47:03

1、shell中数组的定义:

数组名=(value value1 value2 )

也可以单独的设定数组的分量:

arrayL[0]=value

arrayL[1]=value1

2、${arrayL[@/*]}获得数组的所有值

3、${#arrayL[@]}获得数组长度

小例子如下:

#!/bin/bash
arrayList=( )
for i in ${arrayList[@]}
do
echo ${i}
done
echo "the length is ${#arrayList[*]}"

输出:

root@shero-virtual-machine:/home/shero/shell# bash test01.sh
1
2
3
4
5
the length is 5