Guess the number

#! /bin/bash
total=0
num=$((RANDOM%41))
pear(){
read -p "please input number:" a
expr $a + 1 &> /dev/null
if [ $? -ne 0 ];then
echo "please input number;"
pear
fi
}

guess(){
((total++))
if [ $a -eq $num ];then
echo "you guess is rigth."
if [ $total -eq 3 ];then
echo "less than three times."
elif [ $total -gt 3 -a $total -lt 5 ];then
echo " less 5"
elif [ $total -eq 6 ];then
echo "it's many times."
fi
exit 0
elif [ $a -gt $num ];then
echo "$a is bigger than num"
pear
elif [ $a -lt $num ];then
echo "$a is less than num"
pear
fi
}

main(){
pear
while true;do
guess
done
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章