I'm running Mac OS 10.10.3; Emacs is complied and installed via Homebrew; I run it as a GUI application and it reports

This is GNU Emacs 24.4.1 (x86_64-apple-darwin14.1.0, NS apple-appkit-1344.72)
 of 2015-03-23 on boomer

Inside of Emacs shell or Emacs ansi-term, my prompt looks like this:

bash-4.3$ echo $PS1

But inside of Terminal.app, my prompt looks like this:

boomer:~ dgrady$ echo $PS1
\h:\W \u\$

The value of PS1 that Terminal.app sees comes from the system-wide /etc/bashrc file, which reads

# System-wide .bashrc file for interactive bash(1) shells.
if [ -z "$PS1" ]; then

PS1='\h:\W \u\$ '
# Make bash check its window size after a process completes
shopt -s checkwinsize
# Tell the terminal about the working directory at each prompt.
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
    update_terminal_cwd() {
        # Identify the directory using a "file:" scheme URL,
        # including the host name to disambiguate local vs.
        # remote connections. Percent-escape spaces.
        local SEARCH=' '
        local REPLACE='%20'
        local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
        printf '\e]7;%s\a' "$PWD_URL"
    PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"

Why do Bash shells I start from within Emacs not see the same value of PS1?

  • 1
    Do you use the same bash in both cases? Did you install a recent Bash via Homebrew? I'm asking because 4.3 is not the Bash version that comes with OS X…
    – user227
    Commented May 12, 2015 at 5:43
  • @lunaryorn Yes, that's a good point - I did install bash 4.3 from Homebrew, but both Terminal and Emacs are using the new version. (echo $SHELL and echo $BASH both report /usr/local/bin/bash under Terminal.app, Emacs shell, and Emacs ansi-term.)
    – DGrady
    Commented May 12, 2015 at 6:13

1 Answer 1


Terminal.app starts an interactive login shell, while Emacs starts interactive non-login shells. The Bash manual's section on startup files explains that for login shells, Bash will first source /etc/profile (and on Mac OS this file instructs Bash to source /etc/bashrc, which sets PS1) and then goes on to look for user-specific config files. Interactive non-login shells look only for user-specific config files.

One way to check that this is the case: in Emacs,

bash-4.3$ echo $0

while in Terminal.app,

boomer:~ dgrady$ echo $0

Related: https://unix.stackexchange.com/questions/119627/why-are-interactive-shells-on-osx-login-shells-by-default

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.