The disappearance of the variables that you export within your sourced file
is not a feature of the source command. That will happen to ANY command
that changes the shell's internal state, when run in a subshell.

The fact that pipeline components are implicitly run in subshells is
arguably not highlighted well enough, but it IS stated that all components
of a pipeline run in parallel, so it is logically deducible that this must
involve separate processes.

If you need to separate the output of `set -x` from your script's other
output, consider setting BASH_XTRACEFD:

exec 3>> /path/to/xtrace-logfile.txt
BASH_XTRACEFD=3
set -x
source your_file
set +x
exec 3>&-

or in recent versions of Bash:

exec {BASH_XTRACEFD}>> /path/to/xtrace-logfile.txt
set -x
source your_file
set +x
exec {BASH_XTRACEFD}>&-

(This lets Bash choose an available filedescriptor, rather than hard-coding
"3")

-Martin

Reply via email to