bug-bash
[Top][All Lists]
Advanced

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

Re: bash -xv issue with stderr


From: Greg Wooledge
Subject: Re: bash -xv issue with stderr
Date: Sun, 3 Nov 2024 08:36:58 -0500

On Sun, Nov 03, 2024 at 11:28:24 +0100, Christoph Zimmermann wrote:
> Thanks for all the quick reactions on that issue (including microsuxx's
> suggestion which unfortunately does require a CB change).
> 
> If this is intended behaviour, it should be clearly documented on the
> corresponding man page (which doesn't seem to be case ATM).

Hmm... you may have a point there.  The bash man page documents -x as:

              -x      After expanding each simple command, for  command,  case
                      command, select command, or arithmetic for command, dis‐
                      play the expanded value of PS4, followed by the  command
                      and its expanded arguments or associated word list.

whereas POSIX documents it as:

       -x    The shell shall write to standard error a trace for each  command
             after it expands the command and before it executes it. It is un‐
             specified whether the command that turns tracing off is traced.

There's some *implication* that stderr might be the default in the bash
documentation of BASH_XTRACEFD:

       BASH_XTRACEFD
              If  set  to an integer corresponding to a valid file descriptor,
              bash will write the trace output generated when set  -x  is  en‐
              abled  to  that  file descriptor.  The file descriptor is closed
              when BASH_XTRACEFD is unset or assigned a new value.   Unsetting
              BASH_XTRACEFD  or assigning it the empty string causes the trace
              output to be sent to the  standard  error.   Note  that  setting
              BASH_XTRACEFD to 2 (the standard error file descriptor) and then
              unsetting it will result in the standard error being closed.

but I agree that it could be made much clearer that stderr is the default
if BASH_XTRACEFD is never touched.  Perhaps the -x paragraph should say
something like:

              -x      After expanding each simple command, for  command,  case
                      command, select command, or arithmetic for command, dis‐
                      play the expanded value of PS4, followed by the  command
                      and its expanded arguments or associated word list,
                      to the file descriptor contained in BASH_XTRACEFD,
                      or standard error if BASH_XTRACEFD is empty or unset.



reply via email to

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