[Top][All Lists]

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

Re: functions and set -e

From: Paul Jarc
Subject: Re: functions and set -e
Date: Wed, 30 Aug 2006 01:01:06 -0400
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.4 (gnu/linux)

Greg Schafer <address@hidden> wrote:
> Thanks for trying to clarify it for me. Let me put it another way: If I
> change Line 1 above to an if/then style statement instead of "&&" ie:
>   if false; then echo false; fi
> it works exactly like I'd expect instead of the counter-intuitive behavior
> when using &&.

That's because the exit status if an "if" command with a false
condition and no "else" clause is 0, while the status of the "&&"
command is not.

bash is behaving exactly as the documentation says: the function call
itself is a simple command, so if it returns nonzero, bash exits.  The
internal structure of the function is irrelevant.  What matters is the
exit status of the simple command, not how that status is produced
from other, possibly non-simple commands.

If you want the function to never cause bash to exit, insert an extra
"true" at the end.


reply via email to

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