Subject: Re: redirection within sh-like shells
To: None <tech-userlevel@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-userlevel
Date: 08/15/2002 17:02:12
>>>   $ bla >/dev/null 2>&1
>>>   bla: not found
>> Given my understanding of shells and redirection, I can not
>> comprehend why 'sh' does _not_ print the error to /dev/null.  It has
>> been instructed to do so.
> Actually, the shell has been instructed to redirect the output of the
> "bla" command to /dev/null.  Not its own output.

It depends on which way you squint your mind: does that line come from
sh, or from the (failed) bla?  (Conceptually, that is.  It's certainly
being printed by code that's part of the sh executable, in this case.)

That is, is it "do this, and send the resulting output and error to
/dev/null" (with the failure message being a result of "do[ing] this"),
or "do this command with its output and error sent to /dev/null", with
the command never being done because it's not found and thus the
redirection having nothing to operate on?

Redirecting the failure message to /dev/null is both arguably more
useful (otherwise there's no way to shut off failure messages like that
in shell scripts) and more consistent (failure messages generated by
the executed program *are* redirected by such a construct).

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B