The original book This example is to teach debugging script, it deliberately gave a few errors in the script, teach us to understand the system prompts the error, and modify the run. But it's more difficult to write, so put the modified script up, and the script is more interesting
#!/bin/sh
# Hilow--A simple number-guessing game
biggest=100 # Maximum number possible
guess=0 # Guessed by player
Guesses=0 # Number of guesses made
number=$ ($$% $biggest)) # random number, between 1 and $biggest while
[$guess-ne $number]
do echo-n "guess"; read guess
if [$guess-lt $number ] ; Then
echo "... bigger!"
elif ["$guess"-gt $number]; Then
echo "... smaller!i"
fi
guesses=$ (($guesses + 1)) Done
echo "right!! Guessed $number in $guesses guesses. "
Exit 0
Scripting analysis
#1) number=$ (($$% $biggest)) $$ represents the PID that executes this shell because each execution of the shell's PID is not the same, so the number is 1-100 random.
#2) $guess-ne $number, if ["$guess"-lt $number],elif ["$guess"-gt $number]; compare the numbers entered with the $number.
#3) The entire script is not complex, but the logic is clear and interesting.