I have a simple download script and I use set -x
which works great;
I can see each step it performs, and I can identify errors in the script
or in the download:
Assuming bash 4, BASH_XTRACEFD
can be set to override the file descriptor (by default 2, stderr) to which set -x
output is written:
short_date=$(/bin/date +%m%d%y)
exec {BASH_XTRACEFD}>>"$short_date".log
set -x
If running bash 4.0 rather than 4.1 or newer, you have BASH_XTRACEFD but not automatic file descriptor allocation, meaning you'll need to assign one yourself; in the below example, I'm picking file descriptor 100:
short_date=$(/bin/date +%m%d%y)
exec 100>>"$short_date".log
BASH_XTRACEFD=100
set -x
For older releases, your only choice is to redirect all of stderr, rather than only the xtrace stream:
short_date=$(/bin/date +%m%d%y)
exec 2>>"$short_date.log"
set -x