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: Scott Bronson
Subject: Re: Second trap invocation is ignored?
Date: Mon, 6 Apr 2015 08:01:21 -0700

On Mon, Apr 6, 2015 at 5:38 AM, Greg Wooledge <address@hidden> wrote:
> 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

Absolutely right, and I should have included that in my bug report.

That doesn't really help my case though.  Well, I could have my script
echo a trap command to the console and ask the user to re-type it.  :)


> 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

Agreed.  And clearing the debug trap from a script doesn't work:

~$ echo 'trap "echo $1" DEBUG' > foo
~$ echo 'trap - DEBUG' > unfoo
~$ source foo one
one
one
~$ source foo two
one
one
one
~$ source unfoo
one
one
one
~$ source foo three
one
one
one
~$ $(cat unfoo)
one
~$
~$ source foo four
four
four


> 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.)

Yep.  I haven't tried with any traps other than DEBUG, just because
that's the only trap my script needs.  If the maintainers would like
more information about affected traps, I'm happy to investigate.

     - Scott



reply via email to

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