#!/bin/sh -u # $0 number # Play a guessing game on the number. # -IAN! idallen@ncf.ca October 2001 export PATH=/bin:/usr/bin umask 022 if [ $# -ne 1 ]; then echo 1>&2 "Expecting one argument; found $# ($*)" exit 1 fi number="$1" # prompt for the first guess # echo " " echo 1>&2 "Please enter your numeric guess:" read guess echo "Your guess was: $guess" # Loop to test the guess and accept more guesses. # This test statement doesn't handle non-numeric command line # arguments or non-numeric input from the user (a bug). # while [ "$guess" -ne "$number" ]; do # tell how the guess relates to the actual number # echo " " if [ "$guess" -lt "$number" ]; then echo "$guess is smaller than the number" fi if [ "$guess" -gt "$number" ]; then echo "$guess is larger than the number" fi # prompt for the next guess # echo " " echo 1>&2 "Please enter your numeric guess:" read guess echo "Your guess was: $guess" done echo " " echo "Congratulations! You guessed $number correctly!"