bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to inherent non-zero exit status using pipe?


From: Eric Blake
Subject: Re: How to inherent non-zero exit status using pipe?
Date: Wed, 11 Aug 2010 07:53:18 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.8) Gecko/20100805 Red Hat/3.1.2-2.el6 Mnenhy/0.8.3 Thunderbird/3.1.2

On 08/11/2010 07:46 AM, Eric Blake wrote:
> On 08/11/2010 05:20 AM, Pierre Gaston wrote:
>> On Wed, Aug 11, 2010 at 2:18 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
>>> Hi,
>>>
>>>
>>> The following example returns the exit status of the last command in a
>>> pipe. I'm wondering if there is a way to inherent non-zero exit status
>>> using pipe. That is, if there is any command in a pipe that return a
>>> non-zero status, I'd like the whole pipe return a non-zero status.
>>
>> set -o pipefail
> 
> But be aware that you seldom want to use this globally

A less invasive technique is to inspect the array variable
${PIPESTATUS[@]}, which bash maintains for all elements of the previous
pipeline.  But remember, both pipefail and $PIPESTATUS are bash
extensions, and not pure POSIX.

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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