bug-bash
[Top][All Lists]
Advanced

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

Re: Second trap invocation is ignored?


From: Chet Ramey
Subject: Re: Second trap invocation is ignored?
Date: Fri, 10 Apr 2015 11:09:21 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 4/5/15 12:39 PM, Scott Bronson wrote:
> Hi, I don't understand the behavior of the trap command...
> 
>    echo '
>          trap "echo $1" DEBUG
>       ' > ./trapcmd
> 
>    source ./trapcmd first
>    source ./trapcmd second
> 
> I would expect the debug trap to now be 'echo second'.
> However, it's still 'echo first' (full output below).
> 
> Why is the second invocation ignored?  Maybe a bug?

The `source' builtin uses the -T option to decide whether or not to inherit
the DEBUG trap.  If -T isn't set, it saves and restores the DEBUG trap
around calls to `source' and sets the DEBUG trap to the default during the
sourced file's execution.  Unfortunately, that has the side effect of
undoing any changes to the DEBUG trap performed by the sourced file.  You
can work around this for now by running `set -T' before sourcing a file
that modifies the DEBUG trap.

I can think of a couple of workarounds, but that kind of change will have
to wait until the next version of bash.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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