Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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.

share|improve this question
    
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 '12 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 –  John Harper Aug 17 '12 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 '12 at 15:37

4 Answers 4

up vote 5 down vote accepted

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?

share|improve this answer
    
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 '12 at 14:58
    
@ephsmith, my point is ~/.bashrc is typically not executed when starting a new shell. –  Gerry Aug 17 '12 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 '12 at 15:03
    
@ephsmith, I am talking about ~/.bashrc, not /etc/bashrc –  Gerry Aug 17 '12 at 15:05
    
Also, /etc/bashrc is sourced in /etc/profile, that's why it is executed for all shells. –  Gerry Aug 17 '12 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;;
esac

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;;
esac
share|improve this answer

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.

share|improve this answer
    
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 –  John Harper Aug 17 '12 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 '12 at 15:14
    
is your prompt definition after: if [ "$PS1" ]; then </prompt/> fi? –  user1256923 Aug 17 '12 at 15:16
    
/etc/bashrc starts with: if [ -z "$PS1" ]; then return fi PS1='\h:\W \u\$ ' –  John Harper Aug 17 '12 at 15:30
    
why is fi in front of the PS1 definition? also, what about the -z? –  user1256923 Aug 17 '12 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.

share|improve this answer
    
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 '13 at 12:45

Your Answer

 
discard

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.