This script:

#!/usr/bin/env bash

# write child script
echo "export XVAR=xx" > child.sh
echo "YVAR=yy" >> child.sh

# source is piped into tee
source child.sh | tee /dev/null
echo "XVAR=$XVAR"
echo "YVAR=$YVAR"

# source is un-piped
source child.sh
echo "XVAR=$XVAR"
echo "YVAR=$YVAR"



prints this:

XVAR=
YVAR=
XVAR=xx
YVAR=yy


The first 'source' command didn't set variables set or exported in the child.sh script, even though 'source' is executed in the current script's context, and it should behave as if these commands were executed in-place.

Piping source's output into another command shouldn't change its variables-related behavior.


bash-5.2.32



Thanks,

Yuri



Reply via email to