The old boy taught the shell quiz to guess the number game

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.