while(liunx,unix)中的迴圈執行某程式用法

yhdmy發表於2013-04-29
while是用在迴圈執行某程式
格式1:
while 條件;
do
語句
done

格式2:
while true/:/[1]/[0]
do
語句
done

示範1:
COUNTER=0  
while [  $COUNTER -lt 10 ]; do  
    echo The counter is $COUNTER  
    let COUNTER=COUNTER+1   
done
結果1:
The counter is 0
The counter is 1
The counter is 2
The counter is 3
The counter is 4
The counter is 5
The counter is 6
The counter is 7
The counter is 8
The counter is 9

 示範2:
while true
do
date
sleep 3
done
結果2:
Mon Apr 29 23:51:08 CST 2013
Mon Apr 29 23:51:11 CST 2013
Mon Apr 29 23:51:14 CST 2013
Mon Apr 29 23:51:17 CST 2013
Mon Apr 29 23:51:20 CST 2013
Mon Apr 29 23:51:23 CST 2013

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26148431/viewspace-759537/,如需轉載,請註明出處,否則將追究法律責任。

相關文章