Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to set my shell prompt by inserting the following line into .bashrc in my home directory:

export PS1="\[\e[01;36m\][\u]\[\e[0m\] \[\e[01;37m\]\W\[\e[0m\] $ "

I save this file and re-open bash, but it doesn't change. When I issue the command echo $PS1, the console shows

\h:\w$

which is the default prompt. I looked around .bashrc and do not see the PS1 environment variable being set anywhere except the line that I inserted shown above.

This works on my local machine, but with my account on a remote server it won't stick. How do I make the custom prompt go into effect?

Thanks!

share|improve this question
    
Are you sure you are using bash? Try echo $SHELL. –  ssmy Mar 10 '13 at 22:34
    
Yes. On startup, issuing echo $SHELL returns /bin/bash –  Evan W Mar 10 '13 at 22:35
    
Is it possible your .bashrc is being called by .bash_profile or .profile (or that .bashrc is calling them), and so something is overriding them later? –  killermist Mar 10 '13 at 22:55

1 Answer 1

up vote 2 down vote accepted

The problem here is the difference between login and interactive shells. See here for a nice summary.

~/.bashrc is only read when starting an interactive (non-login) shell. When you sshinto a remote machine, you are running a login shell so ~/.bash_profile or ~/.bash_login or ~/.profile (in that order) are read instead. You can check this by running bash after loging on to the remote server, that will start an interactive shell, ~/.bashrc will be read and your modified prompt will appear.

To change the prompt that appears when you ssh, set $PS1 in ~/.bash_profile:

export PS1="\[\e[01;36m\][\u]\[\e[0m\] \[\e[01;37m\]\W\[\e[0m\] $ "

Alternatively, you could call ~/.bashrc from ~/.bash_profile or ~/.profile:

if [ "$BASH" ]; then
  if [ -f ~/.bashrc ]; then
    . ~/.bashrc
  fi
fi

The if [ "$BASH" ]; then is useful when using ~/.profile since it will be read by non-bash shells.

share|improve this answer
    
I've moved the export statement into .profile, but it still doesn't work. I didn't have a .bash_profile file, so I created one and stuck the statement in there, but to no avail. I also tried to run an interactive shell after logging in, but it does not set PS1 either. Do you have any ideas as to what's going on? Thanks for your help! –  Evan W Mar 11 '13 at 2:46
    
@EvanW does it work if you run the export command directly from the terminal? –  terdon Mar 11 '13 at 2:54
    
Ah -- I figured it out. At the end of my .profile file, a shell script was called that modified PS1 again. I moved my export statement to after the source statement calling the script and it works fine. Thank you! –  Evan W Mar 11 '13 at 2:56

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.