bug-bash
[Top][All Lists]
Advanced

[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 09:28:14 +0100

On Mon, Dec 09, 2024 at 11:33:02PM +0100, Andreas Schwab wrote:
> On Dez 09 2024, Mike Jonkmans wrote:
> 
> > But the PIPESTATUS refers to the 'false' pipeline:
> >     $ if false; then :; fi; echo ${PIPESTATUS[*]}
> >     1
> 
> $ if false; then :; fi | true; echo ${PIPESTATUS[*]}
> 0 0
> 
> Why is that not `1 0'?  After all, the last executed commands as part of
> the pipeline (by your reasoning) are `false' and `true'.

My reasoning:

With 'if false... fi | true' there are two pipelines:
1) false
2) (compound command) if | true

The second pipeline, is the last, and that is where PIPESTATUS refers to.
Both parts of the second pipeline have 0 as status.


Confusing is that one could perceive more pipelines.
One for the compoud command (if) and one for the simple command (true).
[ Note that the simple command 'false' is considered a pipeline. ]

Then 'true' might be the "most-recently-executed foreground pipeline".
(term used in `man bash' explaining PIPESTATUS).


Disregarding the 'foreground' aspect.
The "most-recently-executed pipeline" might need some more clarification:
- What is considered a pipeline?
- How to determine 'most-recently-executed'?

--
Regards, Mike Jonkmans



reply via email to

[Prev in Thread] Current Thread [Next in Thread]