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: Chet Ramey
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 09:01:07 -0500
User-agent: Mozilla Thunderbird

On 11/13/24 4:48 PM, Yuri wrote:

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,

The `source' command isn't "executed in the current script's context." It
is executed in a subshell, which can't affect its parent's variables.

The bash man page says:

"Each command in a multi-command pipeline, where pipes are  created,  is
 executed  in a subshell, which is a separate process."

POSIX says:

"Changes made to the subshell environment shall not affect the shell
 environment. Command substitution, commands that are grouped with
 parentheses, and asynchronous AND-OR lists shall be executed in a subshell
 environment. Additionally, each command of a multi-command pipeline is in
 a subshell environment;"

Some shells, including bash in some circumstances, will execute the last
pipeline element in the current shell, but no shell executes the first
element in the current shell context.

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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