[Top][All Lists]

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

Re: weird behavior of set -e

From: Eric Blake
Subject: Re: weird behavior of set -e
Date: Fri, 24 Jun 2011 12:53:50 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110428 Fedora/3.1.10-1.fc14 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.10

On 06/24/2011 03:51 AM, Harald Dunkel wrote:
> Hi folks,
> A colleague pointed me to this problem: If I run
>       ( set -e; ( false; echo x ) )
> in bash 4.1.5, then there is no screen output, as
> expected. If I change this to
>       ( set -e; ( false; echo x ) || echo y )
> then I get "x" instead of "y". How comes?

Because '(false; echo x)' is on the left hand of ||, which disables set
-e for that portion of the command line.  ksh behaves the same way, so
it is not a bash bug.

> Any helpful comment would be highly appreciated.

set -e seldom does exactly what you want - even the writers of POSIX
2008 got it wrong, and here's how they corrected it:


and that's what bash 4.1 implemented.

Eric Blake   address@hidden    +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]