Guess It in Bash Script

Originally contributed to

secretNumber=$(( ((`date +%N` / 1000) % 100) +1 ))
while [ "$guess" != "$secretNumber" ]; do
    echo -n "I am thinking of a number between 1 and 100. Enter your guess:"
    read guess
    if [ "$guess" = "" ]; then
        echo "Please enter a number."
    elif [ "$guess" = "$secretNumber" ]; then
        echo -e "\aYes! $guess is the correct answer!"
    elif [ "$secretNumber" -gt "$guess" ]; then
        echo "The secret number is larger than your guess. Try again."
        echo "The secret number is smaller than your guess. Try again."
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.