Shell programming guessing numbers game. (Master please detour)

Source: Internet
Author: User

Guess the number game. First let the system randomly generate a number, give the number a range (1-60), let the user enter the guessing number, the input to judge, if not meet the requirements, give high or low hint, guess the right after the number of guesses to use, and according to the history of guessing to beat the number of users have guessed, and the key content in a special color to prompt users.

The final results are as follows:

Publish code:

[[email protected] scripts]# cat 7.sh #!/bin/bashi= "$ ((random%60))" Count=0beat () {a=0 b=0 while read line do   If [$line-ge $count] Then ((a++)) Else ((b++)) fi done</tmp/count.log    Echo $a $ ((a+b)) |awk ' {print ($1/$2) *100 "%"} '}while Truedo read-p ' Please enter 1-60 number: num [$num-gt]&&{ echo "is not silly, did not see let you lose 1-60 of the number??? "Continue} [$num-lt 1] &&{echo" is not silly, did not see let you lose 1-60 of the number??? "Continue} expr + $num &>/dev/null [$?] -ne 0] &&{echo "Please enter a number, don't lose it" continue} let count+=1 if [$num-gt $i] then echo-e brothers,    Lose "\033[41;37m Gao \033[0m", Come on! elif [$num-eq $i] Then if [$count-le 3] then echo-e "\033[43;32m Good, ${count} Times is right, defeated the whole Country ' Beat ' people, you can definitely become CEO, win white Rich beauty, embark on the pinnacle of life \033[0m "else echo" with $count times to correct, defeated the national ' Beat ' People "fi echo" $count ">>/tmp/count.log Exit 0 Else        Echo-e brothers, lost "\033[44;37m low \033[0m", Come on! Fidone

Shell programming guessing number games. (Master please bypass)

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.