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?

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.

  • 2
    Well, using ~/.profile is reasonably a more convenient option for non-global variables than conditionals in /etc/profile.d/*.sh. – Gunnar Hjalmarsson Sep 27 '15 at 20:51
  • Which programs read ~/.profile? – dassmann Sep 30 '15 at 13:48
  • This is a Different Question, which should be asked on its own. But, you can ask your system which man pages mention .profile with find /usr/share/man -type f -print0 | xargs -0 zegrep -l '\.profile' and read them. – waltinator Sep 30 '15 at 15:10
  • Good idea to search the man pages for config files. But anyway, I'm not nececarilly root on every system. Any suggestions for that case? – dassmann Nov 16 '15 at 10:18
  • @dassmann: The whole /usr/share/man directory tree is world readable. Why do you think root is needed? – waltinator Nov 25 '15 at 0:25

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.