[root@master code]# cat while.sh
#!/bin/bash
read -p "NUM: " num1
while [ $num1 -gt 0 ]
do
echo "大于"
sleep 3
done
检查输出结果
sh -x while.sh
+ sleep 3
+ '[' 2 -gt 0 ']'
+ echo 大于
大于
+ sleep 3
+ '[' 2 -gt 0 ']'
+ echo 大于
大于
+ sleep 3
检测账户循环
如果不等于root就继续输入账户名称
等于的话接着循环
[root@master code]# cat while.sh
#!/bin/bash
read -p "login: " account
while [ $account != 'root' ]
do
read -p "login: " account
done
文件夹与或非判断
[root@master code]# vim while_folder.sh
如果没有这个文件夹就直接输出not found
#!/bin/bash
while [ ! -d /tmp/baism ]
do
echo "not found /tmp/baism "
sleep 1
done
丈母娘选女婿循环
[root@master code]# cat while_bf.sh
#!/bin/bash
#丈母娘选女婿标准
#1)姑娘带回来第一个男朋友
read -p "money: " money
read -p "car: " car_num
read -p "house: " house
#2)第一个男朋友不满足,进入循环,开始选择模式
while [ $money -lt 100000 ] || [ $car_num -lt 1 ] || [ $house -lt 1 ]
do
echo "不行"
read -p "money: " money
read -p "car: " car_num
read -p "house: " house
done
网友评论