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

  

你可能感兴趣的:(shell while循环体猜数字)