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: Wed, 22 Apr 2015 22:25:00 -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 11:53 PM, Peng Yu wrote:
>> The DEBUG trap is not inherited (set to the default) and restored to its
>> previous value unless the `functrace' option is set:
> 
> For `set -o functrace` or `set -T`, the following example shows that
> commands inside functions inherit the same DEBUG trap as the
> functions. But why 'f' is printed twice after `set -T`.

When a shell function is executed, the DEBUG trap is run at function entry,
so debuggers can trap when the function is executed, rather than just
before the first command in the function body.  At that point, BASH_COMMAND
is still `f'.


> For `declare -t`, I don't see there is any difference. Do I use
> `declare -t` correctly?

Unless you use `-f', each name argument to declare is interpreted as a
shell variable.


> The following example shows that I am able to set the signal for DEBUG
> within a function so that the signal will be able outside the
> function. Isn't it logical to allow the reset of the signal in the
> similar way so that DEBUG signal outside the function will also be
> reset?

http://lists.gnu.org/archive/html/bug-bash/2015-04/msg00051.html

The same explanation applies.  It seems reasonable to make the same
change for function execution.


> Also the man page says "extdebug...  5. Function  tracing  is enabled:
>  command substitution, shell functions, and subshells invoked with (
> command ) inherit the DEBUG and RETURN traps." The following example
> shows no difference on whether extdebug is enabled or not. Why
> functions in `f` are not trapped with the command set for DEBUG at the
> beginning of the script?

Bad documentation; it's never done that.  Maybe it should.

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