#!/bin/bash
#定義一個變量$num,取出1到100的随機值
num=`echo $((RANDOM%100+1))`
i=1
#輸入一個數值($num1)
read -p "please enter integer:" num1
#while循環
while true;do
#使用$num1和$num比較
if [ $num1 -gt $num ];then
echo "The number you entered is too big."
read -p "please enter integer:" num1
elif [ $num1 -lt $num ];then
echo "The number you entered is too small."
#當$num1不等于$num的時候,提示使用者重新輸入$num1
read -p "please enter integer:" num1
else
#當輸入的$num1和$num相同時,輸出"You WIN"
echo "You WIN"
break
fi
#依次遞增,當$num1和$num不相等時繼續循環
let i++
done
#輸出你總共輸出了多少($i)次
echo "You tried $i times"
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicmbw5yN4ETN2cTNzgzMwITOxIDM5EDMy8CXyATOxAjMvwVZsNWa0JXYvwVbvNmLyVGZvNWZy9WbuU2Zh1Wavw1LcpDc0RHaiojIsJye.png)