How to pipe stderr to a command in Bourne or Korn shell

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Tue Oct 9 13:10:13 AEST 1990


In article <1990Oct8.204053.15797 at athena.mit.edu> jik at athena.mit.edu (Jonathan I. Kamens) writes:
>   In csh, one possible way to do it (when working at a tty) would be:

But who said there's a tty around? What if Pim wanted to pipe his output
through yet another command?

> A similar approach will work in sh (and probably ksh), although there's
> probably some better way to do it with various hideous file descriptor
> reassignments (I don't use the bourne shell a lot, so I don't qualify to
> invent hideous file descriptor reassignments :-):

I use the bourne shell a lot, so I guess I qualify. It isn't too
hideous, though, if you write it clearly:

  ( exec 5>&1; exec 1>&2; exec 2>&5; foo ) | err-processor

Even you :-) should be able to recognize the swap idiom there. Start
from basic constructs like this and soon you'll be piping stdout and
stderr through separate commands. Someday you may even learn to use
multitee... [grin]

---Dan



More information about the Comp.unix.shell mailing list