This is an old revision of the document!


SHELL TRICKS

How to redirect stderr but not stdout to a pipe

(taken from csh-whynot)

exec 3>&1; grep yyy xxx 2>&1 1>&3 3>&- | sed s/file/foobar/ 1>&2 3>&-
grep: xxx: No such foobar or directory

Normal output would be unaffected. The closes there were in case something really cared about all its FDs. We send stderr to sed, and then put it back out 2.

internal/shell.1210813722.txt · Last modified: 2008/05/15 03:08 by grg
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate to DokuWiki Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki Powered by OpenVZ Powered by Openwall GNU/*/Linux