This shows you the differences between two versions of the page.
internal:shell [2008/05/15 03:08] grg added URL to csh-whynot |
internal:shell [2008/05/23 05:11] (current) solar made the headings consistent with those on other pages, made the description easier to understand (hopefully) |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | === SHELL TRICKS === | + | ====== Shell tricks ====== |
- | === How to redirect stderr but not stdout to a pipe === | + | ===== How to redirect stderr but not stdout to a pipe ===== |
(taken from [[http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/|csh-whynot]]) | (taken from [[http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/|csh-whynot]]) | ||
- | |||
exec 3>&1; grep yyy xxx 2>&1 1>&3 3>&- | sed s/file/foobar/ 1>&2 3>&- | 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 | grep: xxx: No such foobar or directory | ||
- | Normal output would be unaffected. The closes there were in case | + | grep's normal output (on stdout) will be unaffected. We're closing fd 3 in case a program actually cares about this fd (although most programs don't). We send stderr to sed's stdin, and then put sed's stdout "back" to stderr. |
- | something really cared about all its FDs. We send stderr to sed, | + | |
- | and then put it back out 2. | + |