Shell script: Guessing a number game

Source: Internet
Author: User

[[email protected] ~]# cat guess.sh #!/bin/bash#guess number game;n=$[$ random%100]while :d o    read -p  "Please input a number:   " n1    n2= ' echo  $n 1 | sed  ' s/[0-9]//g '      if [ ! -z  $n 2 ]    then         echo  "Your number is not a number."         continue    fi    if  [  $n 1 ==  $n  ]    then         echo  "You are all right."         break    elif [  $n 1 -GT   $n  ]    then        echo  "bigger."         continue    else         echo  "smaller."         continue    fidone
[Email protected] ~]# sh guess.sh Please input a number:56bigger.please input a number:33bigger.please input a number: 15bigger.please input a number:7smaller.please input a number:10bigger.please input a number:8smaller.please input a nu Mber:9you is all right.



This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1668683

Shell script: Guessing a 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.