[TUHS] On computerese

Chet Ramey via TUHS tuhs at tuhs.org
Tue Sep 17 07:05:09 AEST 2024


On 9/16/24 4:55 PM, Dan Cross wrote:

>> I correctly guessed that only one of thing or otherthing would be printed,
>> but I was not able to guess if the | or the < would take precedence.
>>
>> Is there a simple reason why the < has priority over | for the stdin ?
> 
> I suppose this depends entirely on the shell; perhaps that is the
> point.

POSIX actually speaks on this:

"The standard input, standard output, or both of a command shall be
considered to be assigned by the pipeline before any redirection specified
by redirection operators that are part of the command"

https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_09_02

In the general case, this is how things like

program 2>&1 | collect_stdout_and_stderr

can work (file descriptor 1 is associated with the pipe before fd 2 is
redirected to it).

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet at case.edu    http://tiswww.cwru.edu/~chet/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 203 bytes
Desc: OpenPGP digital signature
URL: <http://www.tuhs.org/pipermail/tuhs/attachments/20240916/ed8377e1/attachment.sig>


More information about the TUHS mailing list