开发者

Bash redirection: since `&> foo` means `> foo 2>&1`, is there a `&>>`?

开发者 https://www.devze.com 2023-03-19 21:15 出处:网络
Following would redirect the Stdout and Stderr to logfile: $ command &> logfile How do I do this redirection without overwrite logfile 开发者_运维知识库during next run of command. Something

Following would redirect the Stdout and Stderr to logfile:

$ command &> logfile

How do I do this redirection without overwrite logfile 开发者_运维知识库during next run of command. Something like >> if it was a plain redirection.


You could attach stderr (2) to stdout (1) and then redirect stdout in append-mode:

command >> logfile 2>&1

The 2>&1 bit attaches stderr to stdout and then you redirect stdout to append to logfile in the usual manner.


From the BASH manual

The format for appending standard output and standard error is:
       &>>word
This is semantically equivalent to
       >>word 2>&1

So, $ command &>> logfile.

EDIT: The shorthand version seems to be a feature in bash version 4, so for compability reasons you should use command >> logfile 2>&1.


According to the documentation, what you're after is what you may have guessed:

$ command &>> logfile

Notice the doubled >> to append.


You answered your question in your question....

$ command &>> logfile
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号