views:

840

answers:

2

My bash init script (~/.profile) contains important initializations, but whenever I use shell-command or compile in emacs, that init file is not read, and without those initialization my bash commands in emacs will fail :( How do I force emacs to execute my init file for the shell that it's using for shell-command?

Clarification: I'm not talking about M-x shell, which reads my init file just fine when I symlinked .profile to .emacs_bash.

+4  A: 

Move your initialization routines into your ~/.bashrc file, and then add the line

source .bashrc

into your ~/.bash_profile file. See the bash man page for a detailed explanation of which startup files get loaded when. They key is the difference between an interactive and non-interactive shell, as well as the difference between a login and a non-login shell.

Adam Rosenfield
I symlinked my .profile to both .bashrc and .bash_profile. Does not seem to work still. Does emacs start an interactive or non-interactive shell? I also tried adding --login to the explicit-bash-args, and still no luck.
polyglot
+1  A: 

Digging through the elisp source; seems like the shell-command in emacs just executes bash -c "command" in my case. Solution is to start emacs (emacs &) in a shell where my .profile is already executed (instead of starting emacs from the GUI menus of my windows manager).

polyglot
Thanks, polyglot, starting emacs from a terminal worked for me as well.
Dave Paroulek