Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make emacs shell execute init file automatically?

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.

like image 938
polyglot Avatar asked Jun 05 '09 21:06

polyglot


1 Answers

Move your initialization routines into your ~/.bashrc file

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. The key is the difference between an interactive and non-interactive shell, as well as the difference between a login and a non-login shell.

In general, .bash_profile is run when logging into the system using a shell while .bashrc is run when starting a new shell (The OS X Terminal application is an exception to this rule as it runs .bash_profile for each new terminal instance). For more info in article form, look here.

like image 123
Adam Rosenfield Avatar answered Oct 05 '22 10:10

Adam Rosenfield