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

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Wed Oct 10 07:04:26 AEST 1990


In article <39936 at shemp.CS.UCLA.EDU> das at lanai.cs.ucla.edu (David Smallberg) writes:
> In article <5069:Oct903:10:1390 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
> >  ( exec 5>&1; exec 1>&2; exec 2>&5; foo ) | err-processor
> Unnecessary subshell creation.

[snif] I feel insulted. No, it does *not* create an extra shell. Perhaps
you should test these things before you post.

This is a good point to remember: certain builtins, such as exec,
correspond directly to system calls between fork() and exec(), and
current shells understand this perfectly.

There's also nothing wrong with using () instead of {} at the beginning
of a pipe; the shell internally surrounds each component of the pipe
with parentheses and then removes redundant levels. (Well, sort of, but
you get the idea.) In fact, {} wastes time, as it requires a semicolon
at the end---something that whoever maintains your script might later
forget.

---Dan



More information about the Comp.unix.shell mailing list