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.

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,

Mike

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.