如何在OS X Leopard上的bash脚本中进行数学约会? [英] How do I do date math in a bash script on OS X Leopard?
问题描述
我意识到我可以启动一个C或Ruby程序来做到这一点,但是我希望我的脚本具有尽可能少的依赖关系.
I realize I could whip up a little C or Ruby program to do this, but I want my script to have as few dependencies as possible.
鉴于 caveat ,如何在OS X上的bash脚本中进行日期数学计算?我在其他网站上看到过一个帖子,其中有人执行了以下操作:
Given that caveat, how does one do date math in a bash script on OS X? I've seen a post (on another site) where someone did the following:
date -d "-1 day"
但这在OS X上似乎不起作用.
But this does not seem to work on OS X.
附录:
好几个人都评论并回答说Ruby,Python,Perl等是OS X的标准配置.我对这三种语言都很熟悉,并且可以轻松编写符合我想要的脚本.实际上,我已经有一个用Ruby编写的脚本.
Several people have commented and responded that Ruby, Python, Perl, and the like come standard with OS X. I'm familiar with all three of these languages and could easily write a script that does what I want. As a matter of fact, I already have such a script, written in Ruby.
所以也许我应该澄清外部依赖"的含义.我的意思是,我不希望我的bash脚本必须调用其外部的任何其他脚本.换句话说,我希望它使用在OS X的原始安装中可用的并且已经在路径中的一些实用程序.
So perhaps I should clarify what I mean by 'external dependency'. What I mean is, I don't want my bash script to have to call any other script external to it. In other words, I want it to use some utility available in a vanilla installation of OS X and already on the path.
但是,看起来这是不可能的,所以我将不得不依靠我的外部依赖项:一个Ruby脚本.
However, it doesn't look like this is possible, so I will have to make due with my external dependency: a Ruby script.
推荐答案
$ date -v -1d
-d设置夏令时标记.
-d sets Daylight Savings time flag.
请尝试约会日期以获取更多信息.
Try man date for more info.
这篇关于如何在OS X Leopard上的bash脚本中进行数学约会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!