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

I use GNU Emacs on Windows and Cygwin for the shell that I do all my work in. The ~/.profile used by Cygwin is ~/.bash_profile. If I start a Cygwin shell by running C:\cygwin\Cygwin.bat, it starts up and executes ~/.bash_profile fine.

I set up Cygwin in GNU Emacs on Windows by putting the following in my ~/.emacs, as prescribed:

;; Set up Cygwin
(add-to-list 'load-path "C:/Program Files/emacs-site-lisp/cygwin")
(require 'setup-cygwin)

C:\Program Files\emacs-site-lisp is where I put my site-wide lisp (obviously).

When I run M-x shell, a Cygwin bash subprocess is created in a buffer named *shell*. Perfect. However, my ~/.bash_profile is not executed.

How do I make the ~/.bash_profile take effect?

share|improve this question
up vote 4 down vote accepted

The best answer I can give is a link that explains the differences between .bash_profile and .bashrc:

There's a whole lot of history there and some of it has to do with The Old Days when we'd dial in to systems with slow modems and we wanted a shell up and running fast. So we'd want to "login" with an environment that was quick to setup and then spawn "sub-shells" that were fully configured because that was faster to do from an already logged in shell.

In your case your inital shell is being started as a login shell (check cygwin.bat -- it's calling bash with --login). But the emacs sub-shell is not being started as a login shell. So only your .bashrc file is being loaded.

These days I think most people just keep it all in .bashrc and have .bash_profile load that instead:

if [ -f ~/.bashrc ]; then
    source ~/.bashrc

But you need to be careful that you don't repeatedly append to variables like PATH if you take this approach. Otherwise, every sub-shell ends up with duplicate entries on the PATH and you can get really long and unruly variables that need to be searched and things slow down.

share|improve this answer
The distinction between .profile and .bashrc has nothing to do with efficiency: they're for different purposes. ~/.profile or ~/.bash_profile is for stuff to do on login, such as setting environment variables and running programs that you want to start once per session. ~/.bashrc is for configuring the interactive shell (aliases, key bindings, etc). The reason why you'd want to source ~/.bashrc from ~/.bash_profile is a design bug in bash: it doesn't read ~/.bashrc in a login shell, even if that login shell is interactive. – Gilles Sep 14 '10 at 18:21

This is how I do it - and it works:

(setq explicit-bash-args '("--login" "--init-file" "c:/home/cbalz/.bash_profile" "-i"))

One would think that 'bash.exe' would run '.bash_profile' without the explicit init file, since this is a login shell ('--login') and 'bash.exe' does properly find and execute '.bashrc'. This is not the case however. Since '.bash_profile' sources '.bashrc', the solution is to just run '.bash_profile'.

I think Cygwin should run a Windows service to manage the environment variables, so that shells could inherit properly.

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.