avd
avd

Reputation: 14461

Changing environment variable in UNIX

If we change an environment variable in one process, is the change reflected in other running processes as well?

Upvotes: 0

Views: 691

Answers (3)

mob
mob

Reputation: 118665

An exception is when you invoke a shell script through the . *filename* [*args*] or source *filename* [*args*] syntax. Any changes made to the environment in these subprocesses scripts are also reflected in the original environment.

Upvotes: 1

Martin B
Martin B

Reputation: 24180

No. The change is only passed on to child processes, and only those started after the change is made. From Wikipedia:

In all Unix and Unix-like systems, each process has its own private set of environment variables. By default, when a process is created it inherits a duplicate environment of its parent process, except for explicit changes made by the parent when it creates the child.

Upvotes: 2

Laurence Gonsalves
Laurence Gonsalves

Reputation: 143314

No. Each process has its own copy of the environment variables. Child processes can inherit environment variables from their parent processes, but these are copies, and so are not altered if the parent's versions are modified.

Upvotes: 5

Related Questions