Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

In Emacs v23.4.1 on my Mac OSX Mavericks, how can Meta-x compile see $PATH for bash as set in my ~/.bashrc? Right now, PATH=/usr/bin:/bin:/usr/sbin:/sbin whereas in a normal shell it is PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/adt-bundle-mac-x86_64-20130522/sdk/tools:/Applications/adt-bundle-mac-x86_64-20130522/sdk/platform-tools:/Applications/adt-bundle-mac-x86_64-20130522/sdk/tools:/Applications/adt-bundle-mac-x86_64-20130522/sdk/platform-tools

Surprisingly, passing bash -c "echo $PATH" to the Compile Command still gives /usr/bin:/bin:/usr/sbin:/sbin.

Why isn't Emacs using my ~/.bashrc for the compile command and is there another init file that it does use that is also used by normal bash shells? What is different about the shell created by the Compile Command.

share|improve this question
One option would be to add just the paths that you need, like this: (setenv "PATH" (concat (getenv "PATH") ":/usr/texbin")) – lawlist Mar 20 '14 at 2:30
@lawlist Yes, but I'm looking to understand why it behaves this way and how to 'fix' it not work around it. – WilliamKF Mar 20 '14 at 2:44
The library contained in this link will give you a start in the right direction to better understanding how to deal with the default behavior: See also this link: (Basically apps launched from Finder inherit their environment from a .plist file rather than the shell environment.) – lawlist Mar 20 '14 at 2:49
Well bash won't normally read your .bashrc and other init files unless you use the login switch (eg,bash -l) – Peon Mar 20 '14 at 3:47
up vote 1 down vote accepted

compile does not invoke .bashrc because compilation uses a non-interactive shell and bash invokes .bashrc when invoked as an interactive non-login shell.

Fortunately, bash does have a mechanism for initializing non-interactive shells via the environment variable BASH_ENV:

When Bash is started non-interactively, to run a shell script, for example, it looks for the variable BASH_ENV in the environment, expands its value if it appears there, and uses the expanded value as the name of a file to read and execute. Bash behaves as if the following command were executed:

if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi

but the value of the PATH variable is not used to search for the file name.

So if you set the BASH_ENV environment variable to $HOME/.bashrc it should invoke your .bashrc in the compile sub-shell.

Setting environment variables for OS X Mavericks applications seems to be a bit of an adventure in itself. I eventually resorted to putting it in my .emacs file, e.g.:

(setenv "BASH_ENV" "$HOME/.bashrc")
share|improve this answer

My current work around is to do:

Meta-x compile source ~/.bashrc; cd ~/myCode/src; make

But, I'd still like to understand why Meta-x compile does not reflect the contents of .bashrc.

share|improve this answer

Your Answer


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.