Using set -x in bash prints shell extended commands to stderr. I would like to redirect them to a file or channel. But not the whole conclusion - only some commands. Something like:
set -x
set -x command.txt ### <-- command.txt param is made up echo $A $B set +x
This will output the debug command. Txt.
Can this be done?
With bash 4.1 or later:
bash
#!/bin/bash exec 5> command.txt BASH_XTRACEFD="5" echo -n "hello " set -x echo -n world set +x echo "!"
Output to standard output (FD 1):
hello world!
Exit to command.txt (FD 5):
+ echo -n world + set +x