while(liunx,unix)中的循环执行某程序用法

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 20:21   3377   0
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/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26148431/viewspace-759537/

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP