shel while循环示例小结
[root@openEuler ~]# cat while4.sh
#!/bin/bash
price=$[ $RANDOM % 100 ]
time=0
while true
do
read -p 'Please enter product price [0-99]: ' input
let time++
if [ $input -eq $price ]; then
echo 'Good luck, you guessed it.'
echo 'You have guessed $time times.'
exit 0
elif [ $input -gt $price ]; then
echo "$input is to high"
else
echo "$input is to low"
fi
if [ $time -eq 5 ]; then
echo "You have guessed is 5 times. exit"
exit 1
fi
done
[root@openEuler ~]# bash while4.sh
Please enter product price [0-99]: 50
50 is to low
Please enter product price [0-99]: 80
80 is to high
Please enter product price [0-99]: 70
70 is to high
Please enter product price [0-99]: 60
60 is to low
Please enter product price [0-99]: 65
65 is to low
You have guessed is 5 times. exit
[root@openEuler ~]#
- .NET Core系列之MemoryCache 初识
- 007手机一键Root(安机网一键Root) v3.0 官方最新版 一键ROOT您的Android手机
- 12306密码被盗了怎么办?12306密码外泄解决方法
- 12个字的qq网名
- 150M迷你型无线路由器怎么设置?
- 192.168.1.1打不开怎么办?路由器192.168.1.1打不开的原因以及解决办法
- 2011年电子报合订本 电子报 编辑部 中文 PDF版 [84M]
- 2015年1月15日小米新旗舰发布会现场图文直播
- 2016.3.1vivo Xplay5新品发布会现场视频直播 优酷直播
- 2016华为P9发布会视频直播地址 4月15日华为P9国行发布会直播