day 9
while 循环
语法:
while 条件;do ...;done
^C [root@iZwz96qzfgxh9l2rk7esxnZ shell]# vim while.sh #!/bin/bash while : do load=`w | head -1 | awk -F 'load average:' '{print $2}' | cut -d . -f1 | sed 's/ //'` if [ $load -gt 10 ] then echo $load fi done ~ |
^C [root@iZwz96qzfgxh9l2rk7esxnZ shell]# vim while2.sh #!/bin/bash |
continue 重复该循环
break 跳出循环
[root@iZwz96qzfgxh9l2rk7esxnZ shell]# vim break.sh [root@iZwz96qzfgxh9l2rk7esxnZ shell]# sh -x break.sh ++ seq 1 5 + for i in '`seq 1 5`' + echo 1 1 + '[' 1 -eq 3 ']' + for i in '`seq 1 5`' + echo 2 2 + '[' 2 -eq 3 ']' + for i in '`seq 1 5`' + echo 3 3 + '[' 3 -eq 3 ']' + break + echo ok ok [root@iZwz96qzfgxh9l2rk7esxnZ shell]# |