help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Inconsistent results of `trap '' EXIT`


From: Eduardo A . Bustamante López
Subject: Re: [Help-bash] Inconsistent results of `trap '' EXIT`
Date: Tue, 20 Feb 2018 09:14:58 -0600
User-agent: Mutt/1.9.3 (2018-01-21)

On Tue, Feb 20, 2018 at 09:02:43AM -0600, Peng Yu wrote:
> The following code shows that `trap '' EXIT` has a different effect
> that depends on whether it has been set before. It is better to make
> `trap '' EXIT` reset the signal instead of using `trap - EXIT`?
> 
> $ trap -p EXIT
> $ trap 'echo abc' EXIT
> $ trap -p EXIT
> trap -- 'echo abc' EXIT
> $ trap '' EXIT
> $ trap -p EXIT
> trap -- '' EXIT

Where is the inconsistency? I only see `trap '' EXIT` being executed once.

Perhaps you are confusing it with `trap - EXIT`?

address@hidden:~$ help trap | grep 'ARG is a' -A3
    ARG is a command to be read and executed when the shell receives the
    signal(s) SIGNAL_SPEC.  If ARG is absent (and a single SIGNAL_SPEC
    is supplied) or `-', each specified signal is reset to its original
    value.  If ARG is the null string each SIGNAL_SPEC is ignored by the
    shell and by the commands it invokes.

The former *ignores* the signal, the latter *resets* it to the original value.

i.e.

address@hidden:~$ trap -p EXIT
address@hidden:~$ trap 'echo abc' EXIT
address@hidden:~$ trap -p EXIT
trap -- 'echo abc' EXIT
address@hidden:~$ trap - EXIT
address@hidden:~$ trap -p EXIT



reply via email to

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