shell while循环体猜数字

#! /bin/bash
echo "guest the num from 1 to 10"
read num
while [ $num != 5 ]
do
if [ $num -lt 5 ]
then
echo "Too small,try agin"
read num
elif [ $num -gt 5 ]
then
echo "Too large,try agin"
read num
fi
echo "bingo"
done

  

[root@lenny Desktop]# ./guest.sh 
guest the num from 1 to 10
4
Too small,try agin
5
bingo

  

posted on 2016-12-12 22:46  leonardhelloworld  阅读(717)  评论(0编辑  收藏  举报

导航