Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run a shell (M-x shell) in, the shell spawned doesn't read (or more specifically, source), /etc/profile during initialization (I have a lot of shell customizations located there).

I've got the path variable set in ~/.MacOSX/environment.plist as is necessary to get to read $PATH, so I have made one of the necessary adaptations to accommodate Emacs to OS X. This doesn't seem to have anything to do with the PATH variable, but rather has to do with the initialization of the shell itself.

share|improve this question
up vote 3 down vote accepted

Ok, here's what I did to solve the problem. It is based an answer to this question from StackOverflow, which I found after mixing up my search terms a little bit on Google. I added the following line to .bashrc:

source /etc/profile

Everything works as it should now.

EDIT: Why the Problem Occurs

I found why you have to explicitly force the BASH shell to read /etc/profile rather than have it read on invocation. Here is the relevant section from the BASH manual (man bash):

When an interactive shell that is not a login shell is started, bash reads and executes commands from ˜/.bashrc, if that file exists. This may be inhibited by using the −−norc option. The −−rcfile file option will force bash to read and execute commands from file instead of ˜/.bashrc.

One can infer from the way this is written (and what it says about how to invoke login shells before this), is that shell.el does not invoke a login shell. I've looked for evidence of this in shell.el and it seems to be true, BASH is invoked with the -i flag (interactive) but not the --login flag. Non-login shells do read .bashrc, so this is why you can work around the problem by putting source /etc/profile into .bashrc.

share|improve this answer
great stuff, it got my .bashrc working again. – Dan Rosenstark Mar 31 '10 at 9:26

You must log in to answer this question.

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