2

I use -x for debug info while executing the shell script.

How can I redirect debug info only to a file?

Example script:

#!/bin/bash
echo OK
echo NO

i will get the below result when i run in debug mode

+ echo OK
OK
+ echo NO
NO

I would like to redirect only the debug info to a file.

+ echo OK
+ echo NO

And runtime output should print on the screen.

OK
NO

marked as duplicate by Jeff Schaller, schily, G-Man, Thomas, roaima Aug 17 '18 at 11:18

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

0

Try this,

 sh -x script.sh 2> out.log