运行程序后,提示用户输入一个0-9的数字,如果是非数字,那么就提示用户输入数字;如果用户猜中,提示用户猜对了;如果用户没有猜中,那么就提示用户重新输入一个数字;如果,用户连续五次都没有猜中,则提示用户,24小时后再来玩这个游戏;
#!/bin/bash
function check() {
if [ $c -eq 5 ]
then
echo "Wait 24 hours."
exit 1
else
continue
fi
}
n2=6
c=0
while :
do
read -p "Please input a number(1-10): " n
n1=`echo $n | sed 's/[0-9]//g'`
if [ -n "$n1" ]
then
tag=2
echo "Just number."
c=$[$c+1]
check
elif [ $n -gt 10 ] || [ $n -lt 1 ]
then
tag=1
c=$[$c+1]
check
echo "The number must great than 1 and less than 10."
else
tag=0
c=$[$c+1]
check
fi
if [ $tag -ne 0 ]
then
continue
elif [ $n -ne $n2 ]
then
echo "Wrong."
c=$[$c+1]
check
else
echo "Right."
exit 0
fi
done