bug-bash
[Top][All Lists]
Advanced

[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 14:16:22 +1000
User-agent: Mutt/1.4.2.1i

On Wed, Aug 30, 2006 at 12:03:51AM -0400, Paul Jarc wrote:
> Greg Schafer <gschafer@zip.com.au> wrote:
> > #!/bin/sh
> > set -e
> >
> > func () {
> >   false && echo false
> >   true && echo true
> >   false && echo false
> > }
> >
> > func
> >
> > echo done
> >
> >
> > It never echoes "done" because func() returns 1.
> 
> That's the correct behavior.  The last "false" within the function
> does not immediately cause bash to exit, since it is part of the "&&"
> comound statement.  But then the function call itself, which is a
> simple command in its own right, has a nonzero exit status, so bash
> exits at that point.

I'll take your word for it.. but I'm not totally convinced. At the very
least, this behavior is very confusing and apparently not documented. It's
just plain weird that the compound statement containing "false" causes the
function call to end up with a nonzero exit status only bacause the
statement appears *on the last line* of the function. The exact same
statement on the first line of the function behaves as expected.

Regards
Greg




reply via email to

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