[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] difference of $? and ${PIPESTATUS[0]}
From: |
Martin D Kealey |
Subject: |
Re: [Help-bash] difference of $? and ${PIPESTATUS[0]} |
Date: |
Mon, 22 Apr 2024 20:37:27 +1200 |
On Mon, 22 Apr 2024, 18:13 felix, <felix@f-hauri.ch> wrote:
> Hi,
>
> Coming on this very old thread:
>
> [the] man page say[s]:
>
> 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).
>
> ? Expands to the exit status of the most recently executed fore‐
> ground pipeline.
>
> If so, "$?" have to be equivalent to "${PIPESTATUS[0]}", I think.
>
> I suggest that man page should be modified to replace "foreground pipeline"
> by "command" under "?" paragraph.
Ironically the description of ? is correct, subject to understanding shopt
-u lastpipe, but the description of LASTPIPE is incongruent with the
meanings of "pipeline", and that the status of a compound command is the
status of its last inner command not counting any command whose status is
checked by the compound command itself (so commands immediately followed by
";do", ";then", or ";else" do not contribute to the status of the compound
command).
On the other hand, LASTPIPE is set after a simple command, ignoring any '!'
or 'time' prefix, or any (explicit or implicit) subshell because a
subshell's exit status is reported via exit+wait in the same manner as a
simple command).
That in turn implies that it will be set after any non-trivial pipeline,
because that forces each of its parts to be executed as a subshell.
-Martin