Hello All,

set -x is useful for me to debug my shell scripts but is there any way to make it write to a file instead of it writing to stderr ?? I do not want to have to do an ,

exec 2> logfile

to retrieve the set -x logs. If I do that, the shell script loses the ability to write to its stderr since all stderr messages generated by set -x and ones that I explicity write to stderr goes to the logfile which I do not want. I want the set -x messages to go to a logfile and still be able to write messages to the stderr of this shell script. Is there any way?? Please help!! Thanks in advance.

9 Years
Discussion Span
Last Post by eggi

Hey There,

I don't know if this is trivial - I couldn't find anything that specifically addressed it, but the easiest way I can think of would be to do a double run:

bash -x script 2>&1|grep "^+" >>debugfile
bash script 2 >>stderrfile

and just sdiff them if you need to. Otherwise, to my knowledge, set -x, or set -o xtrace, doesn't support multiple output streams within itself.

Best wishes,


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.