[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: set -e, bad substitutions, and trap EXIT
From: |
Chet Ramey |
Subject: |
Re: set -e, bad substitutions, and trap EXIT |
Date: |
Wed, 08 Feb 2012 13:44:52 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
On 2/6/12 8:18 PM, Ewan Mellor wrote:
> Hi,
>
> Is this a bug? In the script below, I'm using a variable to control whether
> the script uses set -e or not, because the behavior is dependent on whether
> set -e is set. When the script hits the bad substitution, it runs the exit
> handler and then exits as expected. However, with set -e, the exit status
> for the script as a whole is wrong - it exits with 0 even though the script
> is aborting. That's completely the opposite of what I'd expect. Without set
> -e in force, it all works as expected.
Yes, it's a bug. When -e is in effect, the exit status is not set before
the shell exits. When it isn't, the code path taken results in the correct
exit status.
Here's a patch that solves this particular problem.
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/
err-trap-exit-status.patch
Description: Source code patch