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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.2-patched/subst.c 2011-11-21 12:04:38.000000000 -0500 --- subst.c 2012-02-08 13:36:28.000000000 -0500 *************** *** 7275,7278 **** --- 7281,7285 ---- case '\0': bad_substitution: + last_command_exit_value = EXECUTION_FAILURE; report_error (_("%s: bad substitution"), string ? string : "??"); FREE (value);