Source to Pipe
Piping output of source makes it so ENV variable changes are not reflected in parent process.
When you pipe you create a sub-process. Hence, you env variable changes would not propagate up to parent, since they were only changed in the child process.
Example Code
# scratch1.sh
main() {
SOME_ENV="Scratch1 value"
echo "SOME_ENV: ${SOME_ENV:?} (in Scratch1) (PID: $$, BASHPID: $BASHPID)"
echo "--------------------------------------------------------------------------------Starting source"
source "${SCRATCH_SHELL2:?}" | tee /tmp/out
echo "--------------------------------------------------------------------------------Finished source"
echo "SOME_ENV: ${SOME_ENV:?} (in Scratch1) (PID: $$, BASHPID: $BASHPID)"
}
main "${@}" || exit 1
# scratch2.sh
main() {
SOME_ENV="Scratch2-value"
echo "SOME_ENV: ${SOME_ENV:?} (in Scratch2) (PID: $$, BASHPID: $BASHPID)"
}
main "${@}" || exit 1
Backlinks