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 [email protected] http://cnswww.cns.cwru.edu/~chet/