(Tips & Tricks) Seperate stdout and stderr

February 6, 2011

Seperate stdout and stderr in different shells

Sometimes you want to seperate stdout and stderr.
With the Bourne shell family (sh,bash,ksh,dash) you can use >stdout_file and 2>stderr_file to
do this. For example, if you do not want to see error output you can do:

find / -name ‘*bla*’ 2>/dev/null

With the C-shell family (csh, tcsh) this is a bit different.
You can redirect stdout with ‘>‘ and both stdout and stderr with ‘>&‘ but to seperate both channels you have to run the command in a subshell (using parentheses), for example if you still don’t want to see error output:

( find / -name '*bla*' > /dev/tty ) >& /dev/null 

This workaround redirects stdout to your terminal /dev/tty and with ‘>&‘ both stdout and stderr are redirected to /dev/null. But because stdout was already redirected only stderr ends up in /dev/null.

"To be intoxicated is to feel sophisticated but not be able to say it."

Powered by Wordpress. Theme by Shlomi Noach, openark.org
© 1997 - 2020 KwaLinux Trainingen | Algemene voorwaarden | KvK: 10147727 | BTW-id: NL001873211B65 | Disclaimer