重击保留字与内置命令,并格式化time命令的输出


8

bash保留字和内置命令之间有什么区别?

我可以禁用bash的时间并使用/usr/bin/time吗?如果没有,如何格式化其输出?


1
实际上有一个环境变量:TIMEFORMAT,它指定时间的输出。

Answers:


9

大多数保留字是内置在bash中的命令。如果要使用与保留字同名的可执行文件,则可以指定可执行文件的完整路径,也可以使用反斜杠对命令进行转义。

$ time

real    0m0.000s
user    0m0.000s
sys 0m0.000s
$ \time
Usage: time [-apvV] [-f format] [-o file] [--append] [--verbose]
       [--portability] [--format=format] [--output=file] [--version]
       [--help] command [arg...]
$ then
bash: syntax error near unexpected token `then'
$ \then
bash: then: command not found

另外,BASH FAQ#32:“如何将'time'的输出重定向到变量或文件?”


严格来说,保留字不一定完全是命令,如您的示例所示。
JdeBP 2011年

1

您可以使用builtin <cmd>command <cmd>强制调用内置的bash或外部命令。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.