shell guess the number script

#!/bin/bash

#定一个100以内的随机数
num=$(expr $RANDOM  % 100)
count=0
while :
do
        let count++
        #提示用户输入一个数
        read -ep "请输入一个随机数" shu
        if [ $shu -gt $num ];then
                echo "你猜大啦"
        elif [ $shu -lt $num ];then
                echo "你猜小啦"
        else
                echo "恭喜你,猜对啦!!!"
                echo "你总共猜了$count次"
                break
        fi
done
~             

Guess you like

Origin blog.csdn.net/Q274948451/article/details/108636493