Linux中猜数字shell脚本

简介:
+关注继续查看

利用Linux系统中的时间秒1-59来进行猜数字游戏,详细代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
#author wangning
#date 2017-7-15
#qq 1198143315
#Email 1198143315@qq.com
 
####################################define color##########################
red="\033[31m"
green="\033[32m"
yellow="\033[33m"
color="\033[0m"
 
######################check number if conform 1-59########################
check_number(){
expr $num1 + 1 &>/dev/null
if [ $? -ne 0 ];then
   echo -e "please input $red number $color"
   continue 1
elif [ -z $num1 ];then
   echo -e "$yellow Can't be empty $color"
   continue 2
elif [ $num1 -gt 59 ];then
   echo -e "$green Can't great than 59 $color"
   continue 3
fi
}
 
################################guess number ##############################
guess_number(){
if [ $num1 -gt $num ];then
   echo -e " $yellow too big $color"
elif [ $num1 -eq $num ];then
   echo -e "$green congratulation, you  have guessed ! $color"
elif [ $num1 -lt $num ];then
   echo -e "$green too small $color"
fi
}
 
###############################while circulation################################
main(){
while true
do
num=$(date +%S)
read -p "please input number 1-59:" num1
 
check_number
 
guess_number
done
}
 
main



本文转自 茁壮的小草 51CTO博客,原文链接:http://blog.51cto.com/wn2100/1947812,如需转载请自行联系原作者
相关文章
|
2天前
|
Unix Shell Linux
5 个最常用的 Linux 开源 shell
5 个最常用的 Linux 开源 shell
23 0
|
5天前
|
Shell Linux
用shell脚本记录一个安装Linux软件的脚本
用shell脚本记录一个安装Linux软件的脚本
|
8天前
|
监控 Linux Shell
常用的34个Linux Shell脚本,一定能帮到你(下)
常用的34个Linux Shell脚本,一定能帮到你(下)
|
8天前
|
关系型数据库 MySQL Linux
常用的34个Linux Shell脚本,一定能帮到你(上)
常用的34个Linux Shell脚本,一定能帮到你(上)
|
9天前
|
Java Linux Shell
Linux开发和编程指南:搭建环境、Shell脚本与常见编程语言配置及使用
Linux开发和编程指南:搭建环境、Shell脚本与常见编程语言配置及使用
21 0
|
15天前
|
运维 Unix Shell
Alibaba Cloud Linux操作系统Shell程序
了解Alibaba Cloud Linux Shell和用户Shell定制、C/C++编写一个简单的Shell程序
52 0
|
20天前
|
Shell Linux C++
linux (四)shell脚本(二)终篇
linux (四)shell脚本(二)终篇
16 0
|
20天前
|
物联网 Shell Linux
linux (四)shell脚本(一)
linux (四)shell脚本(一)
19 0
|
23天前
|
Shell Linux
Linux下Shell脚本的调试
这篇博文是对Debugging Shell Scripts in Linux的翻译,希望能帮助到在Linux下写Shell脚本的童鞋。 大多数编程语言都有可用的调试工具,调试工具可用在执行程序或脚本的时候让你检查其内部是如何进行的。对于Shell脚本,我们没有任何可用的调试工具,唯一有的是通过命令行的标识(-n,-v和-x)来辅助我们调试脚本。
28 0
|
2月前
|
缓存 Linux Shell
Linux系列——常用命令与shell函数总结
Linux系列——常用命令与shell函数总结
相关产品
云迁移中心
推荐文章
更多