bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The 'source x' command doesn't keep variables set by x when source o


From: Greg Wooledge
Subject: Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command
Date: Wed, 13 Nov 2024 17:02:31 -0500

On Wed, Nov 13, 2024 at 13:48:18 -0800, Yuri wrote:
> # 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"

> 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.

The commands within a pipeline are executed in subshells (child processes),
so all variable changes are discarded when the subshell exits.

See:
https://mywiki.wooledge.org/BashFAQ/024
https://mywiki.wooledge.org/BashFAQ/106



reply via email to

[Prev in Thread] Current Thread [Next in Thread]