Fun infinite loops: random number guessing: bash #3

An actual game using Terminal on the Mac is something with guessing numbers

Open the Terminal.App from your Mac by holding down command space and typing Terminal


RANDOM=$$
while true
do

echo "can you guess a number between 1 and 10 : "
read
echo The number is :
echo `expr $RANDOM % 9 + 1`
echo

done

can you guess a number between 1 and 10 :
3
The number is :
5

can you guess a number between 1 and 10 :
4
The number is :
5

can you guess a number between 1 and 10 :
9
The number is :
4

can you guess a number between 1 and 10 :
The number is :
3

Control-C to tell the computer to stop, remember the computer is not very smart like humans

See all posts about Fun infinite loops

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s