日期命令不遵循 Linux 规范 (Mac OS X Lion) [英] Date command does not follow Linux specifications (Mac OS X Lion)
问题描述
我已经在我的 linux 机器上开发了一个脚本很长一段时间了,我也想在我的 Mac 上运行它.
I have been developing a script on my linux box for quite some time, and wanted to run it on my Mac as well.
我以为Mac上的功能和linux上的功能是一样的,今天发现不对.我知道 Mac 上存在的功能较少,但我认为确实存在的功能具有相同的实现.
I thought that the functions on the Mac were the same as the functions on linux, but today I realized it was wrong. I knew that fewer functions existed on the Mac, but I thought that the functions that did exist, had the same implementation.
这个问题是专门针对 date
命令的.
This problem is specifically in regards to the date
command.
当我在我的 linux 机器上运行带有参数以提供一些时间(以纳秒为单位)的命令时,我得到了正确的结果,但是当我在我的 mac 上运行它时,它没有那个选项.
When I run the command on my linux machine with the parameter to provide some time in nanoseconds, I get the correct result, but when I run it on my mac, it does not have that option.
Linux-Machine> date +%N
55555555555 #Current time in nanoseconds
Mac-Machine> date +%N
N
如何在 Mac 上以 bash 命令的形式获取以纳秒为单位的当前时间?
How do I go about getting the current time in nanoseconds as a bash command on the Mac?
最坏的情况是我创建了一小段代码,用 C 或其他语言调用系统函数,然后在我的脚本中调用它.
Worst case is I create a small piece of code that calls a system function in C or something and then call it within my script.
非常感谢任何帮助!
推荐答案
这是因为 OSX 和 Linux 使用两组不同的工具.Linux 使用 date
命令的 GNU 版本(因此,GNU/Linux).请记住,Linux 是 Linux,而 OS X 是 Unix.他们是不同的.
This is because OSX and Linux use two different sets of tools. Linux uses the GNU version of the date
command (hence, GNU/Linux). Remember that Linux is Linux and OS X is Unix. They're different.
您可以从 date 命令coreutils/Portfile" rel="noreferrer">MacPorts.它将作为 gdate
安装在您的系统上.您可以使用它,也可以将 date
二进制文件与新的 gdate
二进制文件链接起来;您的选择.
You can install the GNU date
command which is included in the "coreutils" package from MacPorts. It will be installed on your system as gdate
. You can either use that, or link the date
binary with the new gdate
binary; your choice.
这篇关于日期命令不遵循 Linux 规范 (Mac OS X Lion)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!