Home » Questions » Computers [ Ask a new question ]

Emacs and /etc/profile on OS X

Emacs and /etc/profile on OS X

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

Asked by: Guest | Views: 199
Total answers/comments: 1
Guest [Entry]

"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."