[Top][All Lists]

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

Re: weird behavior of set -e

From: Linda Walsh
Subject: Re: weird behavior of set -e
Date: Wed, 04 Apr 2012 16:26:16 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv: Gecko/20100228 Lightning/0.9 Thunderbird/ Mnenhy/

mhenn wrote:

Am 24.06.2011 11:51, schrieb Harald Dunkel:
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?
Any helpful comment would be highly appreciated.


Hey Harald,
Thus, "false" is executed, but the command sequence is not cancelled
because of the "||". Then, after the ";" "echo x" is executed, which
gives a 0 exit status, which leads to "echo y" never to be executed
because of evaluation shortcut of "||". For this, see also:
        man bash | less -p 'The \&\&'


        Has this behavior changed in more recent versions?

The above description seems to be rather non-intuitive, given that ( ) should
mean it is evaluated in a sub-shell process, -- thus whether or not it aborts
after 'false', should be independent of the context.

If it was (set -e; { false ; echo x;} || echo y )
Then I could see {} being a type of parenthesis that allows evaluation
linearly, in the same process and would honor such dependencies.

Or is it the case that the "false;echo x", isn't executed in it's own separate process?

Of course who knows what it does now with the seeming concerted effort to kill
any use or usefulness for the -e switch...(sigh)...

perl has -w and use strict; If you don't want -e to do it, maybe the "language"** should offer alternatives.

**-- I suppose that's the rub -- is it a language as in programming language,
or is it just supposed to be for the most primitive scripting needs.
Adding integers, arrays and hashes sure makes it seem more like a language than
the latter.

reply via email to

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