Hi Lawrence,

2022年10月8日(土) 16:04 Lawrence Velázquez <v...@larryv.me>:
> On Sat, Oct 8, 2022, at 2:11 AM, Koichi Murase wrote:
> > [...]. One thing to note is that the RETURN trap
> > should be cleaned up inside the RETURN trap itself by running `trap -
> > RETURN', or otherwise the RETURN trap is erroneously considered by
> > Bash to be set for the caller function.
>
> The latter behavior is why I didn't describe RETURN as function-local
> in my earlier message, but I forgot the workaround of unsetting
> the trap from within itself.  Nice.

Yeah, that is the tricky point.

> Another strategy is to construct the complete trap string before
> setting the trap, using whichever concatenation methods are preferred:

I think the original idea of ``defer'', RAII, or similar features in
other programming languages is to avoid that (i.e., requiring cleanup
codes in a separate position of the code).

--
Koichi

Reply via email to