bash Mac OS X 上的 awk strftime

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1831093/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 21:27:06  来源:igfitidea点击:

Awk strftime on Mac OS X

macosbashawk

提问by Jeremy White

The following command on my Mac (10.6) gives me an undefined function error:

我的 Mac (10.6) 上的以下命令给了我一个未定义的函数错误:

$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
awk: calling undefined function strftime
 source line number 1

On a Red Hat system, I get the expected result:

在 Red Hat 系统上,我得到了预期的结果:

$ awk 'BEGIN{now=strftime("%D", systime()); print now}'
12/01/09

What's the deal here?

这里有什么交易?

回答by ghostdog74

strftime is a GNU gawk extension. If you want to use strftime, download GNU gawk and install on your Mac. Otherwise, there are other tools like Perl/Python you can use. Check if you have them on your Mac

strftime 是一个 GNU gawk 扩展。如果您想使用 strftime,请下载 GNU gawk 并安装在您的 Mac 上。否则,您还可以使用其他工具,例如 Perl/Python。检查您的 Mac 上是否有它们

回答by 5argon

Use Homebrewand then just run brew install gawk

使用Homebrew然后运行brew install gawk

回答by jamessan

You're relying on an extension to awk that's present in whichever variant (gawk, mawk, nawk, etc.) your Red Hat system happens to be using. See the Standard Unix Specification's awk descriptionfor what you can expect as a baseline for awk.

您依赖于 awk 的扩展,该扩展存在于您的 Red Hat 系统碰巧使用的任何变体(gawk、mawk、nawk 等)中。请参阅标准 Unix 规范的 awk 描述,了解您可以期望作为 awk 的基线。