8

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
1

1 Answer 1

9

Try this,

 sh -x script.sh 2> out.log
1
  • 1
    +1 for how simple and clear this is compared to the resource marked duplicated.
    – saviour123
    Commented Feb 22, 2022 at 13:22