Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following prompt set in my bash_profile:

export PS1='\[\e[1;94m\h:\W \u\e[1;93m\$\e[0m \]'
# default = '\h:\W \u\$ '

Unfortunately, under certain conditions I encounter problems:

  • At a blank prompt, I type a character and then press backspace - the prompt is erased entirely and the cursor goes to the left edge of the terminal instead of simply deleting the character

  • If I use the up and down arrow keys for autocompletion for commands that span multiple lines, only the current line changes but the line above (after the prompt) is left alone

How can I correct my prompt to behave properly in all circumstances as the default one does?

share|improve this question
up vote 2 down vote accepted

You want the \[ ... \] around the nonprinting parts of the prompts (i.e. the escape sequences), not the entire thing. Since you have them around the entire thing, bash can't figure out how much space on screen the prompt takes up, and will redraw the command in the wrong place. Here's what it should be:

export PS1='\[\e[1;94m\]\h:\W \u\[\e[1;93m\]\$\[\e[0m\] '
share|improve this answer
Ahh... makes sense. Thanks so much, this was getting annoying! :) – Jake Petroules Dec 2 '12 at 4:59
Just to clarify Gordons answer, in case you're using colours like in the original question, you need to wrap colour codes with \[ and \]. This applies to any codes that do not print on the screen. – RaviU Apr 16 at 20:39

Your Answer


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.