I wrote an alias for a huge command and stored it in .bash_profile and to my surprise, emacs didn't pick up the alias that I wrote in .bash_profile. After some searching in the internet, I created a .bashrc file in my $HOME with the alias command and only after that emacs picked up the alias. I'm confused because terminal.app takes alias from .bash_profile but emacs takes alias only in .bashrc.

I was running M-x shell and I'm on macOS. Can someone explain me what's the relationship with emacs and .bashrc & .bash_profile.

More to the point, how can I get Emacs to read my .bash_profile in addition to .bashrc?

  • 1
    How did you get Emacs to pick up your .bashrc aliases? I'm asking this because my Emacs (and apparently others') doesn't do it by default. Commented May 8, 2018 at 22:20
  • @ArchStanton see @Vera Johanna answer to this question. That is the same method I used. Though now I'm using zsh instead of bash :) Commented May 9, 2018 at 6:26

2 Answers 2


This is the correct behaviour. .bash_profile is for so-called login shells. Like when you log in to your computer in text mode, or in a terminal emulator to a different computer via ssh or telnet or ...

.bashrc is meant for non-login shells, like when you are already logged in and start a new xterm, or in this case emacs' shell mode.

Usually the .bash_profile contains commands to read in the .bashrc, too:

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

so the .bashrc is read at every startup.

So, aliases belong into .bashrc; it is also customary to create a separate .bash_aliases and include it in .bashrc via the same construct:

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
  • emacs now starts up with zsh so you may consider copying the contents of .bash_profile into .zshrc
    – dr jerry
    Commented May 26, 2023 at 9:09

In addition to the points made by @pingi, you can also use a separate configuration file that will be loaded only for the emacs shell (M-x shell):

From the manual page (emacs) Interactive Shell:

Emacs sends the new shell the contents of the file ‘~/.emacs_SHELLNAME’ as input, if it exists, where SHELLNAME is the name of the file that the shell was loaded from. For example, if you use bash, the file sent to it is ‘~/.emacs_bash’. If this file is not found, Emacs tries with ‘~/.emacs.d/init_SHELLNAME.sh’.

This is useful if you want to use a different shell prompt format within Emacs, or to define functions for passing files to emacsclient.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.