help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Find out trap ERR from within a function when errtrace i


From: Patrick Schleizer
Subject: Re: [Help-bash] Find out trap ERR from within a function when errtrace is unset?
Date: Wed, 25 Feb 2015 18:51:18 +0000

Chet Ramey:
> On 2/25/15 10:31 AM, Patrick Schleizer wrote:
>> Hi!
>>
>> TLDR:
>>
>> If errtrace is not in use, and one is within a function, is it possible
>> from within the function to find out which trap ERR is set on global level?
> 
> No, unless you have saved any existing trap into a variable that you can
> interrogate from within the function.  That's the reason for errtrace:
> to allow a way to circumvent the usual ERR trap inheritance rules.  Bash
> functions don't have local trap state otherwise.
> 

Thanks, Chet!

I found an acceptable workaround to this issue. "If errtrace is enabled,
store the eventually previously configured trap and restore it at the
end. Otherwise just use local traps." In other words...

init function:
- store previously existing trap
- disable errtrace if it's set

every other function:
- use local trap within the function

deinit function:
- re-enable errtrace if it was set
- restore stored trap




reply via email to

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