help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why`trap DEBUG` has no effect if it is called inside a f


From: Chet Ramey
Subject: Re: [Help-bash] Why`trap DEBUG` has no effect if it is called inside a function?
Date: Tue, 21 Apr 2015 21:54:43 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

On 4/21/15 9:44 PM, Peng Yu wrote:
> Hi,
> 
> The following examples show that if `trap DEBUG` is called inside the
> function resetdebugsig, it will not able to reset the DEBUG signal
> outside the function. However, this problem does not exist for the
> signal EXIT. Can anybody help me understand why there is a difference
> between DEBUG and EXIT in this aspect?

The DEBUG trap is not inherited (set to the default) and restored to its
previous value unless the `functrace' option is set:

"All other aspects of the  shell  execution  environment  are  identical
between  a function and its caller with these exceptions: the DEBUG and
RETURN traps (see the description  of  the  trap  builtin  under  SHELL
BUILTIN  COMMANDS below) are not inherited unless the function has been
given the trace attribute (see the description of the  declare  builtin
below)  or  the -o functrace shell option has been enabled with the set
builtin (in which case all  functions  inherit  the  DEBUG  and  RETURN
traps),  and the ERR trap is not inherited unless the -o errtrace shell
option has been enabled."

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