Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

bash

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.

like image 643
jay Avatar asked Feb 24 '23 15:02

jay


2 Answers

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.

like image 155
mu is too short Avatar answered Mar 04 '23 20:03

mu is too short


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.

like image 22
carlpett Avatar answered Mar 04 '23 22:03

carlpett