5

What I have observed:

When I type emacs in gnome-terminal, it launches in the same environment, with variables set in .bashrc. If I use a keyboard shortcut to the command emacs, it opens in an environment that does not have these variables.

Questions:

  1. Is there a reason for this behaviour?
  2. How can I get emacs to open in an environment with settings from .bashrc?
  3. If I have root access, can I set these variables 'system-wide'?

Additional background: I need is to be able to access the variables from within R, as described in a related SO question (How to access a bash environment variable from within R in emacs), and I also need the path to my texlive distribution for Auctex. The present question is different in that I am more generally interested in the difference between launching emacs from within the terminal and launching emacs from the Applications menu, Gnome-do, or keyboard shortcut that call either emacs or /usr/bin/emacs23 %F.

1 Answer 1

10

~/.bashrc is usually read for secondary interactive shells after you log in. If you want to initialise your parameters on login the use ~/.profile instead. To apply you parameters system-wide use /etc/profile. It's the first file read by bash.

To make things clearer I think I'd explain a bit more.

  • When you login, your login shell reads first the global /etc/profile, then ~/.profile and parameters/variables mentioned there are initialised. However you don't see this shell as terminal because the X-window system GUI is running.
  • After login when you open a secondary terminal/terminal-emulator e.g. gnome-terminal ~/.bashrc is read and and the parameters/variables declared in it are available to the secondary terminal only. Note that this secondary terminal is a child process of your login shell.
  • When you launch an application from menu, it's executed as a child process of your login shell and it inherits the parameters from it's ancestor process. But .bashrc was not available for the main login shell; so it's not available for applications too. So anything in .bashrc won't be available for those applications if run from menu. But when you open a gnome-terminal and executes command from there, applications are launched as children of gnome-terminal and inherits .bashrc's parameters from it.
2
  • This fixes my problem (+1) but doesn't really answer my question.
    – Abe
    Jun 13, 2012 at 15:20
  • I've edited my answer to reflect the changes.
    – Samik
    Jun 13, 2012 at 15:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .