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: Greg Wooledge
Subject: Re: Second trap invocation is ignored?
Date: Mon, 6 Apr 2015 08:38:40 -0400
User-agent: Mutt/1.4.2.3i

On Sun, Apr 05, 2015 at 09:39:50AM -0700, 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).

Without the source shenanigans, it works:

imadev:~$ trap 'echo first' DEBUG
imadev:~$ echo hi
first
hi
imadev:~$ trap 'echo second' DEBUG
first
imadev:~$ echo hi
second
hi

As soon as I try your source trick, things start to break down:

imadev:~$ echo 'trap "echo $1" DEBUG' > foo
second
imadev:~$ source ./foo one
second
imadev:~$ echo hi
second
hi

But if I clear the DEBUG trap first, then it starts to work:

imadev:~$ trap - DEBUG
second
imadev:~$ echo hi
hi
imadev:~$ source ./foo one
imadev:~$ echo hi
one
hi

So, if there is a bug here, it's got something to do with setting traps
in a sourced file, when that type of trap is already set.  (Also, I
didn't try with any other traps.  Maybe it's specific to DEBUG.)



reply via email to

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