echo "大家猜猜0-9的随机数,你一共有3次机会"
count=2
n=$((RANDOM%10))
while ((count>=0))
do
read -p "please input:" num
if (($n==$num))
then
echo "congratulation!随机数是$n,你总共猜了$((3-$count))次"
exit
elif ((n<num))
then
if (($count==0))
then
echo -n "high"
else
echo "high,还有$count次机会"
fi
else
if (($count==0))
then
echo -n "low"
else
echo "low,还有$count次机会"
fi
fi
((count--))
done
echo "可惜,你猜了三次,没机会了"
echo "随机数是$n"
本文出自 “爱武装一辈子” 博客,请务必保留此出处http://menglinux.blog.51cto.com/8733806/1439172
原文地址:http://menglinux.blog.51cto.com/8733806/1439172