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 16:53:43 -0500
User-agent: Mozilla Thunderbird

On 12/9/24 12:21 PM, Ulrich Müller wrote:

Bash Version: 5.2
Patch Level: 37
Release Status: release

Description:
        For a compound command like "if" or "while" and with
        an unsuccessful test, the last element of PIPESTATUS is not the
        return status of the compound but that of the test command.
        For example, "if false; then :; fi" returns 0 but ${PIPESTATUS[0]}
        is 1.

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 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]