shell数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#! env sh


list1=(1 2 3 "hello")

list2=(
1
2
"hello"
)


#赋值,下标不限制范围
list2[5]='No_5'
list2[4]='No_4'


#角标也从0开始
echo ${list1[0]} ${list1[1]} ${list1[2]} ${list1[3]}

echo ${list2[@]}

#获取元素个数
echo ${#list2[@]}
echo ${#list2[*]}

#获取某元素长度
echo ${#list2[5]}

转载请注明来源 https://tianweiye.github.io