1 #!/bin/bash 2 a=$(expr $RANDOM % 100) #生成一到一百的随机数 3 echo $a #打印随机数 4 b=0 5 while true 6 do 7 let b++ 8 echo "比较了第$b次!" 9 read -p "请输入一个1-100的随机数数: " num 10 if [ $num -gt 100 ]; then 11 echo "输入错误!请重新输入!" 12 continue 13 elif [ $num -le 100 ]; then 14 if [ $num -lt $a ]; then 15 echo "sorry,小了" 16 elif [ $num -gt $a ]; then 17 echo "sorry,大了" 18 elif [ $num -eq $a ]; then 19 echo "恭喜,俩个数相等,获得大奖" 20 break 21 fi 22 fi 23 done