[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PIPESTATUS differs from $? for compound command
From: |
Mike Jonkmans |
Subject: |
Re: PIPESTATUS differs from $? for compound command |
Date: |
Tue, 10 Dec 2024 10:41:58 +0100 |
On Tue, Dec 10, 2024 at 09:28:31AM +0100, Ulrich Müller wrote:
> >>>>> On Mon, 09 Dec 2024, Mike Jonkmans wrote:
>
> >> Why is `if false; then :; fi' not a pipeline? It is a command, and the
> >> components of a pipeline are commands.
>
> > It is a pipeline indeed, but not the last
> > (doc says: most-recently-executed).
> > The last is the 'false' simple command/pipeline.
>
> Then what about these?
>
> $ true; case a in esac
> $ echo "ret = $?, status = ${PIPESTATUS[*]}"
> ret = 0, status = 0
>
> $ false; case a in esac
> $ echo "ret = $?, status = ${PIPESTATUS[*]}"
> ret = 0, status = 1
>
> "case a in esac" is a one-command pipeline, and certainly it is executed
> after "false". So it should qualify as "the most-recently-executed
> foreground pipeline (which may contain only a single command)".
It is indeed confusing.
Also compare:
$ if false; then echo foo; fi
$ echo "ret = $?, status = ${PIPESTATUS[*]}"
ret = 0, status = 1
To:
$ if ! :; then echo foo; fi
$ echo "ret = $?, status = ${PIPESTATUS[*]}"
ret = 0, status = 0
The '! :' is a pipeline with status = 1.
Yet it is not reflected in PIPESTATUS.
I think that 'most-recently-executed pipeline' needs some clarification.
Seemingly a compound command is not considered a pipeline,
when there is no simple command ran.
Moreover, the '!'-part of a pipeline is not influencing PIPESTATUS.
--
Regards, Mike Jonkmans
- Re: PIPESTATUS differs from $? for compound command, (continued)
- Re: PIPESTATUS differs from $? for compound command, Mike Jonkmans, 2024/12/09
- Re: PIPESTATUS differs from $? for compound command, Andreas Schwab, 2024/12/09
- Re: PIPESTATUS differs from $? for compound command, Dale R. Worley, 2024/12/09
- Re: PIPESTATUS differs from $? for compound command, microsuxxor, 2024/12/09
- Re: PIPESTATUS differs from $? for compound command, Dale R. Worley, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, Mike Jonkmans, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, Andreas Schwab, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, microsuxxor, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, Ulrich Müller, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, microsuxxor, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command,
Mike Jonkmans <=
- Re: PIPESTATUS differs from $? for compound command, Phi Debian, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, Chet Ramey, 2024/12/10
- Re: PIPESTATUS differs from $? for compound command, Mike Jonkmans, 2024/12/11
- Re: PIPESTATUS differs from $? for compound command, Andreas Schwab, 2024/12/11
- Re: PIPESTATUS differs from $? for compound command, Lawrence Velázquez, 2024/12/11
- Re: PIPESTATUS differs from $? for compound command, Mike Jonkmans, 2024/12/12
- Re: PIPESTATUS differs from $? for compound command, Lawrence Velázquez, 2024/12/12
- Re: PIPESTATUS differs from $? for compound command, Mike Jonkmans, 2024/12/12
- Re: PIPESTATUS differs from $? for compound command, microsuxxor, 2024/12/12
- Re: PIPESTATUS differs from $? for compound command, Chet Ramey, 2024/12/12