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

David Smallberg das at lanai.cs.ucla.edu
Wed Oct 10 10:47:06 AEST 1990


Dan Bernstein writes:
>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.

My apologies.  It's been a while since I've done this kind of stuff under sh,
but I remember that at one time (could be many years ago) there really was an
extra process creation.  As recently as a few months ago, I reported a
situation in which ksh88d could be clever enough to do an exec without a fork,
but wasn't -- I haven't checked yet to see if ksh88e "fixes" it.  So I guess
I trust the shells to do the clever thing less often than they deserve to be
trusted.

>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.

That's certainly true for builtins.  But as I noted above, even current shells
don't always "understand" some constructs perfectly.  (By "understand", I mean
understand to the point where a fairly obvious unnecessary fork can be
eliminated.)
--

-- David Smallberg, das at cs.ucla.edu, ...!{uunet,ucbvax,rutgers}!cs.ucla.edu!das



More information about the Comp.unix.shell mailing list