让 bash 脚本了解假期
我正准备开始编写 bash 脚本(作为 bash 新手)。该脚本的目的是强制要求某些其他命令(即脚本的工作部分)不在假期运行。
我在网上找到了下面的代码段在线:
#!/bin/bash
grep -i date holiday.txt
if[ $? -ne 0] then;
#script to run the jobs
exit
fi
虽然我承认我是 bash 新手,但我似乎看不出这个脚本有什么问题 - 但同时,它看起来有点太“简单化” - 有没有我未经训练的眼睛无法发现的“陷阱”现在现货,但稍后会来咬我的屁股吗?
我正在运行 GNU bash,版本 4.1.5(1)-release
I was about to embark on writing a bash script (as a bash newbie). The purpose of the script is to be enforce the requirement that some other commands (i.e. the work part of the script) dosen't run on holidays.
I found the snippet below online:
#!/bin/bash
grep -i date holiday.txt
if[ $? -ne 0] then;
#script to run the jobs
exit
fi
Although I admit I am a bash neophyte, I can't seem to spot anything wrong with this script - yet at the same time, it looks a little too "simplistic" - are there any "gotchas" that my untrained eye cannot spot now, but will come to bite me in the rear later on?
I am running GNU bash, version 4.1.5(1)-release
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假期.txt 的示例
example of holiday.txt
对我来说看起来很好,除了语法之外,除了我不确定你想要屏幕上的输出。您可能更喜欢
在原始代码中,我认为您需要交换
;
和then
并在[
之前添加空格。另外,如果代码很短
,也许更方便的方法。
Looks fine to me, except for syntax and except for I'm not sure you want the output on the screen. You may prefer
In original code I think you need to swap
;
andthen
and add space before[
.Also, if the code is short
maybe more convenient way to do it.