A: Repeat until the game is won

   1 #!/bin/bash
   2 
   3 ## Starting message
   4 echo "Welcome to the Guessing Game."
   5 
   6 ## Initialize our variables
   7 number=$RANDOM
   8 guess=0
   9 
  10 ## Repeat until the game is won
  11 while [ $guess -ne $number ] ; do
  12 
  13     ## Get the next guess
  14     echo "What is your guess?"
  15     read guess
  16 
  17     ## Respond with the hint
  18     echo -n "Your guess of $guess is "
  19     if [ $guess -eq $number ] ; then
  20         echo "corrent."
  21     elif [ $guess -lt $number ] ; then
  22         echo "too low."
  23     elif [ $guess -gt $number ] ; then
  24         echo "too high."
  25     fi
  26 
  27 done

Scripting_Bash_Intro/212 A: Repeat until the game is won (last edited 2009-09-08 13:49:28 by MarkSuter)