码迷,mamicode.com
首页 > 系统相关 > 详细

linux的shell脚本猜数字1-100小游戏

时间:2018-09-05 20:00:55      阅读:667      评论:0      收藏:0      [点我收藏+]

标签:break   read   ash   while   bin   inux   case   The   rand   

#!/bin/bash echo ‘可以输入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 fi done echo ‘你有输入正确选择,默认退出‘

linux的shell脚本猜数字1-100小游戏

标签:break   read   ash   while   bin   inux   case   The   rand   

原文地址:http://blog.51cto.com/13956220/2170859

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!