for語句循環shell
[root@xuexi-001 ~]# for i in `seq 1 5`; do echo $i;done 1 2 3 4 5 [root@xuexi-001 ~]# for i in `seq 1 5` > do > echo $i > done 1 2 3 4 5
[root@xuexi-001 ~]# a=5 [root@xuexi-001 ~]# if [ $a -gt 3 ] > then > echo ok > fi ok
腳本形式bash
[root@xuexi-001 shell]# vi if1.sh #!/bin/bash a=5 if [ $a -gt 3 ] then echo ok fi [root@xuexi-001 shell]# sh if1.sh ok
[root@xuexi-001 shell]# cp if1.sh if2.sh [root@xuexi-001 shell]# vi if2.sh #!/bin/bash a=1 if [ $a -gt 3 ] then echo ok else echo nook fi [root@xuexi-001 shell]# sh -x if2.sh + a=1 + '[' 1 -gt 3 ']' + echo nook nook [root@xuexi-001 shell]# sh if2.sh nook
[root@xuexi-001 shell]# cp if2.sh if3.sh [root@xuexi-001 shell]# vi if3.sh #!/bin/bash a=2 if [ $a -gt 4 ] then echo ">1" elif [ $a -lt 6 ] then echo "<6 && >1" else echo nook fi [root@xuexi-001 shell]# sh if3.sh <6 && >1 [root@xuexi-001 shell]# sh -x if3.sh + a=2 + '[' 2 -gt 4 ']' + '[' 2 -lt 6 ']' + echo '<6 && >1' <6 && >1 [root@xuexi-001 shell]#