shell if....then,很好的一个学习代码,一眼就明白了
for循环
1 #!/bin/bash 2 #数字性循环 3 #第一种 4 for((i=1;i<=10;i++)); 5 do 6 echo $(expr $i \* 3 + 1); 7 done 8 # 9 # 10 # 11 ##第二种 12 for i in $(seq 1 10) 13 do 14 echo $(expr $i \* 3 + 1); 15 done 16 # 17 # 18 ##第三种 19 for i in {1..10} 20 do 21 echo $(expr $i \* 3 + 1); 22 done 23 # 24 # 25 ##第四种 26 awk 'BEGIN{for(i=1; i<=10; i++) print i}' 27 # 28 # 29 ##字符性循环 30 ##第一种 31 for i in `ls`; 32 do 33 echo $i is file name\! ; 34 done 35 # 36 ##第二种 37 for i in $* ; 38 do 39 echo $i is input chart\! ; 40 done 41 # 42 # 43 ##第三种 44 for i in f1 f2 f3 ; 45 do 46 echo $i is appoint ; 47 done 48 # 49 ##第四种 50 list="rootfs usr data data2" 51 for i in $list; 52 do 53 echo $i is appoint ; 54 done 55 # 56 # 57 ##路径查找 58 ##第一种 59 for file in /home/cyl/下载/*; 60 do 61 echo $file is file path \! ; 62 done 63 # 64 ##第二种 65 for i in $(ls *.sh) 66 do 67 echo $file is file path \! ; 68 done View Code
转载于:https://www.cnblogs.com/cyl2008/p/11222628.html