Linux shell script guess number 1-100 mini-game

Source: Internet
Author: User
#!/bin/bashecho ‘可以输入q或者quit退出‘a=$[RANDOM%100+1]while :; do read -p ‘请输入一个数字(1-100):‘ num i=`echo $num | sed ‘s/[0-9]//g‘` if [ -z "$num" ];then echo ‘不能什么都不输入‘ continue fi if [ $num == q ] || [ $num == quit ];then exit 2 fi if [ ! -z "$i" ];then echo ‘你输入的不是数字‘ continue fi if [ $num -lt 1 ] || [ $num -gt 100 ];then echo ‘你输入的数字不再1-100内‘ continue fi if [ $num -lt $a ];then echo ‘猜错了,太小了‘ elif [ $num -gt $a ];then echo ‘猜错了,太大了‘ else echo ‘恭喜你,猜对了‘ read -p ‘还想再来一局吗,请输入yes或者no:‘ ab case $ab in yes) continue ;; no) exit ;; *) break ;; esac fidoneecho ‘你有输入正确选择,默认退出‘

Linux shell script guess number 1-100 mini-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.