I have a bash script with output that I'm trying to debug by running bash with -x
. I'd also like the output to be redirected to stdout instead of stderr (because the logging framework we use treats all stderr content as high-priority errors).
However, command substitutions in my code are failing because the lines logged by set -x
are getting mixed in with the actual intended output, as shown in the below log.
How can I avoid this bug while directing set -x
logs to stdout?
Example:
root@ee0d2037fdca:/# $(echo "ls")
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
root@ee0d2037fdca:/# set -x
root@ee0d2037fdca:/# export BASH_XTRACEFD=1
+ export BASH_XTRACEFD=1
+ BASH_XTRACEFD=1
root@ee0d2037fdca:/# $(echo "ls")
+ ++ echo ls ls
bash: ++: command not found
root@ee0d2037fdca:/#