1、shell中数组的定义:

    数组名=(value value1 value2 )

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

   arrayL[0]=value

  arrayL[1]=value1

 

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

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

 

小例子如下:

#!/bin/bash
arrayList=(1 2 3 4 5)
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

相关文章:

  • 2021-06-07
  • 2022-02-13
  • 2021-09-04
  • 2021-12-03
  • 2021-08-21
  • 2021-10-23
  • 2021-12-20
  • 2021-09-19
猜你喜欢
  • 2021-10-02
  • 2021-07-20
  • 2021-11-10
  • 2021-07-09
  • 2021-06-03
  • 2021-11-03
  • 2021-04-11
相关资源
相似解决方案