[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: |
Martin D Kealey |
Subject: |
Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command |
Date: |
Thu, 14 Nov 2024 14:40:54 +1000 |
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
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, (continued)
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Greg Wooledge, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Yuri, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, #!microsuxx, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Greg Wooledge, 2024/11/13
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command,
Martin D Kealey <=
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Yuri, 2024/11/14
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/14
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Martin D Kealey, 2024/11/15
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Robert Elz, 2024/11/16
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Martin D Kealey, 2024/11/16
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Oğuz, 2024/11/16
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/16
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Martin D Kealey, 2024/11/18
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Oğuz, 2024/11/18
- Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command, Chet Ramey, 2024/11/19