Using set -x in bash prints the shell-expanded commands to stderr. I would like to redirect these to a file or pipe. But not the whole output - only some comman
set -x
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 stdout (FD 1):
hello world!
Output to command.txt (FD 5):
+ echo -n world + set +x