登录  | 加入社区

黑狼游客您好!登录后享受更多精彩

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

查看: 487|回复: 0

手把手教你在Linux下制作有趣的shell脚本(26)

[复制链接]

 成长值: 35935

8169

主题

7094

帖子

6831

现金

黑狼创办人

Rank: 12Rank: 12Rank: 12

积分
6831
发表于 2017-10-27 11:35:16 | 显示全部楼层 |阅读模式 来自 美国
手把手教你在Linux下制作有趣的shell脚本(26)

大家好,今天是周五了,马上就双休了,是不是有点小激动了呢?
今天大家可能也比较忙了,毕竟明天该休息了,这周的工作完成了多少进度了呢?
不会才完成50%吧?兄弟,你是要加班的节奏了啊。。。
今天说点轻松的脚本吧。
Itt2n6pYnnN06CgN.jpg
##==========================##
今天和大家分享一个猜数字的脚本。
如果之前有学习过编程语言的小伙伴应该对这样的效果很熟悉了吧。
好吧,我就不废话了,开始今天的代码分享了吧。
下面的是今天要分享的代码:
#!/bin/bash
# Arthor : anjingdeshinian
# Time : 2017-10-26
#
n=$[$RANDOM%100]
while :
do
read -p "please input a number: " n1
n2=`echo $n1 | sed 's/[0-9]//g'`
if [ ! -z $n2 ]
then
echo "your number is not a number."
continue
fi
if [ $n1 == $n ]
then
echo "you are all right."
break
elif [ $n1 -gt $n ]
then
echo "bigger."
continue
else
echo "smaller."
continue
fi
done
这就是今天要和大家分享的代码了。
yxx9yrbi93MbYYK3.jpg
-下面是运行出来的效果:
please input a number: 11
smaller.
please input a number: 55
smaller.
please input a number: 66
smaller.
please input a number: 77
smaller.
please input a number: 99
bigger.
please input a number: 88
bigger.
please input a number:
好了,今天和大家分享的就到这里吧。
今天下班,可能好多同学都会很忙吧。。。嘿嘿。。
明天不上班,大家今天晚上好好休息啊。。。
大家,明天见。
w114dy7hrY2ZLE7r.jpg




上一篇:Shell脚本,自动化发布tomcat项目
下一篇:Linux shell脚本特殊变量分析整理,系统管理员必备
您需要登录后才可以回帖 登录 | 加入社区

本版积分规则

 

QQ|申请友链|小黑屋|手机版|Hlshell Inc. ( 豫ICP备16002110号-5 )

GMT+8, 2024-5-15 22:18 , Processed in 0.064738 second(s), 47 queries .

HLShell有权修改版权声明内容,如有任何爭議,HLShell將保留最終決定權!

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表