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: Chet Ramey
Subject: Re: PIPESTATUS differs from $? for compound command
Date: Tue, 10 Dec 2024 17:10:08 -0500
User-agent: Mozilla Thunderbird

On 12/10/24 4:41 AM, Mike Jonkmans wrote:

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.

OK, extend that. The `!' applies to the pipeline, not necessarily to all
the commands in it, since the status of a pipeline is the status of the
last element (ignore pipefail for now).

So, given

! true | false

how should the negation be reflected in the values assigned to PIPESTATUS?

Since one use of PIPESTATUS is to find out which pipeline element(s)
succeeded and which failed, how is modifying some element of PIPESTATUS
here helpful?

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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