Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Global xtrace from function



* Bart Schaefer (Sun, 20 Jul 2014 09:09:10 -0700)
> 
> On Jul 20,  5:20pm, Thorsten Kampe wrote:
> }
> } is it possible to `setopt xtrace` from within a function without 
> } having xtrace unset when exiting the function? That seems to be the 
> } default behaviour for Bash's `shopt -os xtrace`.
> 
> The options XTRACE, PRINT_EXIT_VALUE, LOCAL_OPTIONS, and LOCAL_LOOPS
> are always reset on exit from a function.  (I'm not sure why the
> LOCAL_TRAPS and LOCAL_PATTERNS options aren't in that list as well,
> except "because they're newer and nobody thought of it.")  Zsh has
> behaved this way since before the source was under version control.
> 
> It's possible that we ought to skip resetting xtrace when in posix
> shell emulation mode.
> 
> You can get the effect you want with
> 
>     this_sets_xtrace() { trap 'setopt xtrace' EXIT }
> 
> except of course in posix emulation (POSIX_TRAPS), when exit traps
> aren't executed for shell functions ...

Works beautifully, thanks!



Messages sorted by: Reverse Date, Date, Thread, Author