1

The environment variables of a program differ on whether it is started from a terminal or from the desktop (by clicking on its icon).

For example: I use bash and have specific variables set in my .bashrc for development purposes. When I start my editor of choice (sublime text, but this is true for any program) from the command line everything works fine. When I start it from the desktop (gnome 3 in this case), the variables are missing.

So my question is: What is the correct way to define variables that are honored by the desktop and the terminal alike?

dassmann
  • 503

1 Answers1

0

The variables in your .bashrc are only set up by a bash shell, which, if the variables are exported, stores the vars and their values in its environment, and passes a copy this environment to any process it starts. Starting sublime text from the desktop does not invoke bash to read .bashrc. You could set the variables globally by defining (and exporting) them in a user.sh file in /etc/profile.d (you will have to create /etc/profile.d/user.sh). If you are on a multi-user system, you could surround the definitions with if [[ "$USER" = "me" ]] ; then ... fi, so that everybody else (if that's a non-empty set) doesn't suffer with your definitions. Look at the other scripts in /etc/profile.d for hints.

To see process relationships, and environment inheritance, one could

pstree -a -c -l -p -u 1

and, of course, man pstree.

waltinator
  • 37,856