天天看點

shell 猜數字大小

[[email protected] ~]# cat guess.sh

#!/bin/bash

prive=$(expr $RANDOM % 1000)

echo $prive

count=1

while true

do

read -p “請輸入一個1-1000的随機數:” num

if [ $num -gt $prive ]; then

echo “大了”

elif [ $num -lt $prive ]; then

echo “小了”

else

echo “兩個數相等”

echo $count

exit 0

fi

let count++

done

shell 猜數字大小