以下代码将把标准输出和标准错误重定向到
我该如何在下次运行
logfile
中:$ command &> logfile
我该如何在下次运行
command
时不覆盖 logfile
进行重定向?类似于普通重定向的 >>
。logfile
中:$ command &> logfile
command
时不覆盖 logfile
进行重定向?类似于普通重定向的 >>
。来自BASH手册
The format for appending standard output and standard error is:
&>>word
This is semantically equivalent to
>>word 2>&1
那么,$ command &>> logfile
。
编辑:简短的版本似乎是bash 4版本中的一个特性,因此出于兼容性考虑,您应该使用command >> logfile 2>&1
。
您可以将stderr(2)附加到stdout(1),然后以追加模式重定向stdout:
command >> logfile 2>&1
2>&1
位将标准错误输出附加到标准输出,然后您可以像通常一样将标准输出重定向以追加到logfile
。2>&1
。 - mu is too short你在问题中回答了自己的问题...
$ command &>> logfile
&>>
是 bash-4 的东西,我猜 jay 正在使用的是仍然附带 bash-3 的 OSX。 - mu is too short
syntax error near unexpected token '>'
。 - mu is too short2>&1
版本应该在任何地方都可以工作。 - mu is too shortbash --version
) - carlpett