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

Re: Suppress tracing of "set +x"



On Fri, 5 Feb 2016 10:27:35 +0000
Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Fri, 5 Feb 2016 11:09:02 +0100
> Dominik Vogt <vogt@xxxxxxxxxxxxxxxxxx> wrote:
> >   set -x
> >   some command
> >   RC=$?
> >   { set +x; } 2>/dev/null
> >   test ! x$RC = x0 && exit $RC
> > 
> > I want only "some command" traced, not "RC=$?".  Yet I have to do
> > it before the "set +x" because the latter overwrites $?.  Any
> > ideas how to get around this?
> 
> () {
>    setopt localoptions xtrace
>    some command
> }

Drifting a bit away from the original topic... I tried to improve this
so you didn't get the "(anon)" in the PS4 output, instead something more
useful.  I came up with this...

  () {
    setopt localoptions promptsubst
    PS4=${PS4//\%N/'${funcstack[2]:-$0}'}
    setopt xtrace
    # some command
  }

This sort of works, but it struck me that it's harder than it might be
to get the name of the top level script.  If you run the above from the
command line, funcstack is one deep with just the "(anon)", and $0 is
also "(anon").  I couldn't see a way of getting what the value of the
scriptname name would be at the top level.  Am I missing something?
Should funcstack show this (I vaguely expected it would) or is this
going to cause other problems?

pws



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