On 9/14/10 3:44 AM, Jochen Dekeyser wrote:
> Bash Version: 4.1
> Patch Level: 7
> Release Status: release
> 
> Description:
>         Run this script:
> 
>         #!/bin/bash
> 
>         trap 'echo "trap error on ${LINENO}"' ERR
>         trap 'echo "trap exit on ${LINENO}"' EXIT
> 
>         /bin/false
> 
>         exit 0
> 
>         You should get (and this is also the result you get in Bash 3.2):
> 
>         trap error on 6
>         trap exit on 8
> 
>         But you get:
> 
>         trap error on 6
>         trap exit on 1

This was changed in bash-4.0 with the rationale that traps, except the
special bash traps, should be run in a semi-independent environment with
a private value of $LINENO.  As a result, $LINENO gets reset before
running the trap.

I guess you could make a case to not reset $LINENO for the exit trap
due to this sentence in Posix (though $LINENO is not Posix):

"The environment in which the shell executes a trap on EXIT shall be
identical to the environment immediately after the last command executed
before the trap on EXIT was taken."

I'll have to think about it.

-- 
``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/

Reply via email to