1, guess the number: first let the system randomly generated a number, give this number to a range (the number of the first 50 and 50), let the user input guess the number, the input judgment, if not meet the number to give high and low hint, according to the tips, see how many times you can guess right?
Answer:
The works of the Cheng students in the 23 period
1. Realize the effect
[Email protected] scripts]# sh apple.sh
How much is the apple a kilo?
Please guess the number 0-60
Please enter your Price: 58
Hey, why don't you buy it at this price?
How much is the apple a kilo?
Please guess the number 0-60
Please enter your Price: 40
Too low too low
How much is the apple a kilo?
Please guess the number 0-60
Please enter your Price: Oldgirl
Don't tease me, just guess the numbers.
How much is the apple a kilo?
Please guess the number 0-60
Please enter your Price: 42
Guess right, that's 42 bucks.
 
2, Implementation script:
#!/bin/bashnum=$ (date +%s) echo "Current Apple price is $num yuan per catty" echo "========================" sleep 1clearipple () {echo ' How much is this apple a kilo? Please guess 0-60 of the number ' read -p ' Please enter your price: " Aexpr $A + 1 &>/dev/nullif [ $? -ne 0 ] then echo "Don't tease me, just guess the Numbers" ipplefi}guess () { if [ $A -eq $NUM ] then echo "guessed right, is $num yuan" exit 0 elif [ $A -gt $NUM  ]          THEN &NBsp; echo "Hey, why don't you buy it at this price?" " ipple elif [ $A -lt $NUM ] then echo "too low and too low"         IPPLE         FI} Main () {Ipplewhile truedo guessdone}main
This article is from the "Old boy Linux ops" blog, please be sure to keep this source http://oldboy.blog.51cto.com/2561410/1686781
The old boy taught the shell quiz to guess the number game