[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Another new 4.0 feature? functions can't return '1', (()) can't eval
From: |
Chet Ramey |
Subject: |
Re: Another new 4.0 feature? functions can't return '1', (()) can't eval to 0? |
Date: |
Tue, 09 Aug 2011 19:42:05 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11 |
On 8/8/11 11:43 PM, Linda Walsh wrote:
> I have a function that returns true/false.
>
> during development, (and sometimes thereafter depending on the script, I
> run with -eu, to make sure the script stops as soon as there is a
> problem (well, to 'try' to make sure, many are caught.
>
> But there are two instances that cause an error exit that seem pretty
> unuseful and I don't remember them breaking this way before.
The change to make (( honor the `errexit' option came in with bash-4.1,
part of the cleanup after the Posix changes to the specification of the
behavior of `set -e'. Most of the other changes in this area came in
with bash-4.0.
Posix changed set -e to cause the shell to exit when any command fails,
not just when simple commands fail, as in versions of the standard up
to and including Posix.1-2008. There are the usual exceptions (command
following if, commands preceding && and ||, and so on). This was
changed for better alignment with historical versions of the shell and
to reconcile differences between implementations.
> 2) a function returning a false value -- Tried putting the ((expr)) in
> an if:
>
> if ((expr)); then return 0; else return 1;
>
> As soon as it sees the return 1, it exits, -- as I returned 'false'
> (error).
This should have always been the case -- a function is a simple command,
so its returning a non-zero exit status should cause the shell to exit.
This was true even before Posix changed.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/