-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patharray.sh
More file actions
executable file
·60 lines (53 loc) · 1.24 KB
/
Copy patharray.sh
File metadata and controls
executable file
·60 lines (53 loc) · 1.24 KB
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
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Xiang Wang @ 2016-03-27 19:57:04
array=(red green blue yellow magenta)
# array=(`ls`)
len=${#array[*]}
echo "The array has $len members. They ars:"
i=0
while [ $i -lt $len ]; do
echo "$i: ${array[$i]}"
let i++
done
for i in $( ls ); do
echo $i
done
for i in "cmatrix" "python2"; do
echo $i
done
# 过滤掉列表中的某一个
echo "输出array的列表"
array=(string1 string2 string3)
for i in ${array[*]};
do
echo $i
done
# 退出多重循环
line1=(string1 string2 string3)
line2=(string4 string2 string1)
for i in ${line1[*]};
do
echo "查看line1的${i}"
for j in ${line2[*]};
do
echo "查看line2的${j}"
if [ $i == $j ]; then
echo "line1的${i}和Line2的${j}相同"
break 2 # break后面的数字代表停多少次循环, 默认为1
fi
done
done
echo "# 继续单重循环"
for i in ${line1[*]};
do
echo "查看line1的${i}"
for j in ${line2[*]};
do
echo " 查看line2的${j}"
if [ $i == $j ]; then
echo " line1的${i}和Line2的${j}相同, 不再循环Line2"
continue 2 # break后面的数字代表停多少次循环, 默认为1
fi
done
echo "line1的${i}处理结束"
done