Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect all stderr in bash?

Tags:

linux

bash

shell

I'm looking for a way to redirect all the stderr streams in interactive bash (ideally to its calling parent process).

I don't want to redirect stderr stream from each individual command, which I could do by appending 2> a_file to each command.

By default, these stderr streams are redirected to the stdout of an interactive bash. I would like to get them on the stderr of this interactive bash process in order to prevent my stdout to be polluted by error messages and be able to treat them separatly.

Any ideas?

I still haven't found an answer ... But maybe it's actually a tty parameter. Does anybody knows something about tty/interactive shell responsibility for handling stderr ?

like image 279
Grégoire Cachet Avatar asked Aug 27 '08 13:08

Grégoire Cachet


People also ask

How do I redirect stderr?

The regular output is sent to Standard Out (STDOUT) and the error messages are sent to Standard Error (STDERR). When you redirect console output using the > symbol, you are only redirecting STDOUT. In order to redirect STDERR, you have to specify 2> for the redirection symbol.

How do I redirect both standard and standard error on the same location?

Discussion. &> or >& is a shortcut that simply sends both STDOUT and STDERR to the same place—exactly what we want to do.


1 Answers

Use the exec builtin in bash:

exec 2> /tmp/myfile

like image 86
gavrie Avatar answered Oct 15 '22 10:10

gavrie