[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PIPESTATUS differs from $? for compound command
From: |
Dale R. Worley |
Subject: |
Re: PIPESTATUS differs from $? for compound command |
Date: |
Wed, 11 Dec 2024 22:00:47 -0500 |
My opinions on this subject:
It's probably not worth changing the behavior, particularly since there
is likely to be some small amount of code out there that depends on it.
The behavior in regard to ! is correct (as has been noted) because
PIPESTATUS records the values of the commands in the pipeline, not of
the pipeline as a whole.
Someone noted that "! true | ! true" is a syntax error, which matches
the documentation.
Chet Ramey <chet.ramey@case.edu> writes:
> Compound commands don't generally set PIPESTATUS. Multi-element pipelines
> (the original purpose, because otherwise why bother), simple commands
> (single-element pipelines) including shell builtins, and compound commands
> that resemble simple commands (`[[', `((') set it.
>
> Yes, you can make the case that compound commands are pipelines, and,
> according to the grammar, they are, but their status is always available
> in $?, and they never have more than one status value.
The documentation is (as of 5.1):
PIPESTATUS
An array variable (see Arrays below) containing a list of exit
status values from the processes in the most-recently-executed
foreground pipeline (which may contain only a single command).
This needs to be modified to note that compound commands that are not
one component of a multi-command pipeline do not cound as pipelines
for setting PIPESTATUS. Exactly which compounds commands don't set
PIPESTATUS is not obvious. E.g. "{...}" does not but "(...)" does.
"processes" should probably be changed to "commands" as that's what
they're called in the documentation.
"most-recently-executed foreground pipeline" should be clarified as
"most-recently-completed foreground pipeline".
Dale
- Re: PIPESTATUS differs from $? for compound command, (continued)
Re: PIPESTATUS differs from $? for compound command, Chet Ramey, 2024/12/10
Re: PIPESTATUS differs from $? for compound command,
Dale R. Worley <=