0

I can set environment variables to be inherited by all processes in ~/.profile. This works because the desktop environment (eg. gnome-shell) runs this file on login. gnome-shell then updates its own environment variables. Because each process (firefox, xterm, emacs) has gnome-shell as an ancestor, they inherit these environment variables.

Is there a way to update the environment variables in this process (gnome-shell) after login? I envision something like

$ xdg-set FOO=BAR

then in a new terminal you can immediately see

$ echo $FOO
BAR
0

The environment is passed to a new process in a similar manner as the command line arguments are: they are copied into the new process' address space. They are not passed "by reference", so a change in some ancestor process' environment is not reflected in the descendant processes.

This means you can only change the environment of a process by manipulating the process itself, and only if the process offers a means to do so, e.g. setting a variable in a shell. This change in the environment is then typically reflected in any child processes the process might spawn.

1
  • Yes, I only care about new processes spawned. – extremeaxe5 Apr 13 '20 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.