[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: functions and set -e
From: |
Greg Schafer |
Subject: |
Re: functions and set -e |
Date: |
Wed, 30 Aug 2006 15:22:24 +1000 |
User-agent: |
Mutt/1.4.2.1i |
On Wed, Aug 30, 2006 at 01:01:06AM -0400, Paul Jarc wrote:
> Greg Schafer <gschafer@zip.com.au> 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.
That is the crux of the problem. I was expecting the function to return
zero.
But as you quite rightly say, the exit status of the "&&" command in this
instance is nonzero and this is the key point I was missing. It's covered in
the "Lists of Commands" section of the manual:
"The return status of AND and OR lists is the exit status of the last
command executed in the list."
Ok, sorted. Thanks for your patience. I'm gonna put this down as a trap for
young players :-)
Regards
Greg