help-bash
[Top][All Lists]
Advanced

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

Re: reset a trap upon use


From: Koichi Murase
Subject: Re: reset a trap upon use
Date: Sat, 25 Nov 2023 01:48:25 +0900

2023年11月25日(土) 1:16 bill-auger <bill-auger@peers.community>:
> [...]
> just wanted to know if this is the expected behavior (or did my predecessor 
> write a bug
> by placing the trap reset inside of the cleanup() function)

It is the expected behavior.  The traps for DEBUG, RETURN, and ERR
pseudo-signals are maintained for each function call separately.
Unless `set -T' (for DEBUG and RETURN) or `set -E' (for ERR) is
specified or the trace attribute (`declare -t') is specified to the
function (for DEBUG and RETURN), those traps for the pseudo-signals
will not be inherited by the child calls of the function.  On the
other hand, non-empty traps will be propagated to the callers.  To
make a function inherit the RETURN trap of the caller and propagate
the unset RETURN to the caller, you need to mark the function with the
trace attribute.  More specifically, you need to mark your `cleanup'
as

declare -ft cleanup

--
Koichi



reply via email to

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