Trying to change my command prompt in OS X 10.8 / Mountain Lion. Changes to ~/.bashrc and ~/.bash_profile do not make any difference. Like:

export PS1="\W \$"

It defaults to the host name ("\h\%"). Even if I try to set PS1 in the terminal, it changes but displays the variables literally, as below:

ws10% PS1="\W \$"
\W $

(with ws10 being the host name)

My ~/.bashrc file:

export PS1="\W \$ "

Any ideas? I keep getting lost when I cd up and down the directory structure! Thanks a lot.

  • Clearly the bashrc in your home directory is getting sourced since you're seeing the changes to your prompt. At this point, I'd recommend copying the system bashrc from /etc and starting fresh. Edit the PS1 variable after copying it over.
    – ephsmith
    Aug 17, 2012 at 15:17
  • I don't think bashrc is getting sourced... the changes to bashrc don't show up in the terminal at all. The change above was from literally typing PS1 at the command prompt Aug 17, 2012 at 15:20
  • Okay. That's a potentially different problem. ~/.profile really is a good place for this. Regardless, you should see the update if you export PS1 at the commandline. Strange.
    – ephsmith
    Aug 17, 2012 at 15:37

4 Answers 4


Typically on Mac OS X, only .bash_profile is executing when starting a new terminal. A common solution is to source one file into the other, for example in ~/.bashrc:

[ -r ~/.bash_profile ] && source ~/.bash_profile

Apart from that, your example works perfectly fine for me when put in .bash_profile. If you still experience problems, maybe you are overlooking something else?

  • But default value for PS1 in Mac OS is set in /etc/bashrc. It's done conditionally--i.e if PS1 exists (it's a login shell) then PS1 is assigned a value. All that happens in bashrc.
    – ephsmith
    Aug 17, 2012 at 14:58
  • @ephsmith, my point is ~/.bashrc is typically not executed when starting a new shell.
    – Gerry
    Aug 17, 2012 at 14:59
  • try moving your profile or bash_profile to bashrc and see what happens. It is sourced for all shells--not just login shells.
    – ephsmith
    Aug 17, 2012 at 15:03
  • @ephsmith, I am talking about ~/.bashrc, not /etc/bashrc
    – Gerry
    Aug 17, 2012 at 15:05
  • Also, /etc/bashrc is sourced in /etc/profile, that's why it is executed for all shells.
    – Gerry
    Aug 17, 2012 at 15:07

I copied my .bashrc and .profile from an old mac and was seeing this issue. It came down to the fact that .bashrc was checking for a specific terminal emulation name "xterm-color". In Mountain Lion, xterm-color was renamed to xterm-16color and a new xterm-256color emulator was added:

check to see if your .bashrc has this check:

case "$TERM" in
    xterm-color) color_prompt=yes;;

and add the new term names, so it looks like this:

case "$TERM" in
    xterm-color)    color_prompt=yes;;
    xterm-16color)  color_prompt=yes;;
    xterm-256color) color_prompt=yes;;

My .bashrc reads:

PS1="\[\e[0;32m\]\u@monkey:\w\$ \[\e[0m\]" 

i.e. no 'export' in front of the PS1 setting. Does it help? I surely get the prompt I have specified. In addition this line

source ~/.bashrc

in .bash_profile should also help is you set the prompt in .bashrc.

  • PS1="\[\e[0;32m\]\u@monkey:\w\$ \[\e[0m\]" gives me a new command prompt of \[\e[0;32m\]\u@monkey:\w$ \[\e[0m\] ... just copied/pasted that from my terminal Aug 17, 2012 at 15:13
  • The only difference would be that without the export, your prompt will not be set in child processes (for example when executing /bin/bash to start a new shell).
    – Gerry
    Aug 17, 2012 at 15:14
  • is your prompt definition after: if [ "$PS1" ]; then </prompt/> fi? Aug 17, 2012 at 15:16
  • /etc/bashrc starts with: if [ -z "$PS1" ]; then return fi PS1='\h:\W \u\$ ' Aug 17, 2012 at 15:30
  • why is fi in front of the PS1 definition? also, what about the -z? Aug 17, 2012 at 15:36

In .bash_profile add at the end following line:

[ -r ~/.profile ] && source ~/.profile

That made it work again for me under Mountain Lion.

  • Or just move the contents of ~/.profile to ~/.bash_profile. If both ~/.bash_profile and ~/.profile exist, bash only reads ~/.bash_profile when it is invoked as an interactive login shell.
    – Lri
    Nov 20, 2013 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .