1. 程式人生 > >shell編程--while循環

shell編程--while循環

while shell 循環

腳本

[root@lynn-04 shell]# vim while2.sh

#!/bin/bash
i=6
while [ $i -gt 0 ]
do
    i=$[$i-1]
    echo $i
done

執行結果

[root@lynn-04 shell]# sh while2.sh
5
4
3
2
1
0

腳本

[root@lynn-04 shell]# vim while1.sh

#!/bin/bash
load=`w|head -1|awk -F ‘load average: ‘ ‘{print $2}‘|cut -d. -f1`
while [ $load -lt 10 ]
do
    echo $load
    /usr/lib/zabbix/alertscripts/mail.py 15******[email protected] "load high" "$load"
    exit
done

執行結果 這裏是發郵件的腳本 當然我的郵箱也會收到報警郵件

[root@lynn-04 shell]# sh while1.sh
0

shell編程--while循環