bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'set -e' and 'trap 0' togheter does not work as expected on syntax e


From: Chet Ramey
Subject: Re: 'set -e' and 'trap 0' togheter does not work as expected on syntax errors
Date: Fri, 21 Aug 2009 22:39:33 -0400
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)

Stefano Lattarini wrote:
> I have the following scripts:
>  
>  $ cat nobug.sh
>  trap 'e=$?; [ $e -gt 0 ] && echo "OK" || echo "BAD"; exit $e' 0
>  # syntax error here
>  && true
> 
>  $ cat bug.sh
>  set -e
>  trap 'e=$?; [ $e -gt 0 ] && echo "OK" || echo "BAD"; exit $e' 0
>  # syntax error here
>  && true
> 
> I thought that when bash detect a syntax errors in the script,
> it would pass a $? != 0 to the code in the exit trap, regardless
> of whether `set -e' is active or not.

It's not exactly a bug -- this behavior isn't standardized anywhere,
and historical shells behave differently.  The behavior you want is
useful enough that I'll change it for bash-4.1, though.

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/




reply via email to

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