#! /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 }