Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 7 down vote accepted

~/.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.
share|improve this answer
    
This fixes my problem (+1) but doesn't really answer my question. –  Abe Jun 13 '12 at 15:20
    
I've edited my answer to reflect the changes. –  Samik Jun 13 '12 at 15:58
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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