-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.sh
More file actions
50 lines (43 loc) · 918 Bytes
/
array.sh
File metadata and controls
50 lines (43 loc) · 918 Bytes
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# **********************************************************
# * Author : xoyabc
# * Email : lxh1031138448@gmail.com
# * Last modified : 2019-03-28 23:24
# * Filename : array.sh
# * Description : more than one element
# **********************************************************
# REF:
# https://www.jianshu.com/p/543fa9df3469
# https://blog.csdn.net/ee230/article/details/48316317
# traverse a two-dimensional array
# method 1
ip_array=(
200 ZR
201 ZR
202 ZR
203 ZR
)
len=${#ip_array[@]}
echo "len is $len"
for((i=0;i<len;i+=2))
do
echo $i
ip=${ip_array[i]}
role=${ip_array[i+1]}
echo "${ip_array[i]} , ${ip_array[i+1]}"
echo "ip is $ip, role is $role"
done
# method 2 (recommended)
declare -a TEST
TEST=(
'1 2'
'3 4'
'5 6'
)
for i in "${TEST[@]}"
do
b=($i)
url=${b[0]}
host=${b[1]}
echo "url:$url,host:${host}"
done