Tag Archives: random

Bash Guessing Game

Here is a game that is worth your time. You even get to code it yourself.

Lolz. Needs a bash interpreter.

~$ nano guessinggame.sh

Paste this in there.

#!/bin/bash
echo “Please pick an integer between 1 and 10.”
read guess
number=0
while [ “$number” -le 1 ]
do
number=$RANDOM
let “number %= 11 ”
done

if [ $guess -eq $number ]
then
echo “You win!”
else
echo “You suck. The number was $number.”
fi

exit

Then make it executable.

~$ chmod +x guessinggame.sh

Now you have yourself a dandy.

Run it like so.

~$ ./guessinggame.sh

This game does not have any input validation. If you try to guess a letter or special character, you will get an error. Guessing out of the bounds of 1 to 10 will also greatly reduce your odds of winning.