How do I do date math in a bash script on OS X Leopard?

后端 未结 8 919
迷失自我
迷失自我 2021-02-03 21:15

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.

Given that caveat, how does one d

8条回答
  •  盖世英雄少女心
    2021-02-03 21:32

    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.

    Doing in C or as a Ruby script would result in less dependancies, and be more cross-platform.. Bash-scripting just calls various other scripts/applications, mainly the GNU utilities.. Many of the commands are unavailable, or take different arguments on other platforms (especially between OS X and Linux)..

    Ruby is included by default on OS X Leopard (and 10.4, and probably previous versions if I recall correctly), and if you use Rubys built-in date libraries, it will work consistently on any platform.

    Whenever you try to do anything remotely complicated, you are generally best of using a "proper" scripting language!

提交回复
热议问题