|
From: | Yuri |
Subject: | The 'source x' command doesn't keep variables set by x when source output is piped into other command |
Date: | Wed, 13 Nov 2024 13:48:18 -0800 |
User-agent: | Mozilla Thunderbird |
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=yyThe 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
[Prev in Thread] | Current Thread | [Next in Thread] |