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've set PS1 to the following value:

PS1="\033[0;37m[\033[1;33m\w\033[0;37m]\n\t \[[34m\]\u\033[0;37m@\[[34m\]\[[1m\]\h\[(B[m\] $"

The problem is that any command spanning more than a line loops around and don't generate a new line. So I overwrite the line that I already have typed. What is wrong with the PS1?

share|improve this question

migrated from Jul 17 '11 at 12:03

This question came from our site for professional and enthusiast programmers.

that's not even a valid command, bash waiting for more input – yi_H Jul 17 '11 at 10:59
up vote 5 down vote accepted

Non-printing characters in the prompt need to be surrounded by \[ and \] so that bash can properly track the length of the prompt and accommodate lines that go beyond the edge of the terminal.

share|improve this answer
SO I should add before and after which parts of the line? – Runar Jul 17 '11 at 20:52
You add it before and after the parts that don't print, as many times as required. – Ignacio Vazquez-Abrams Jul 17 '11 at 20:53
But the line do print, but when i type in a long command it loops. – Runar Jul 17 '11 at 20:54
CHARACTERS. Try again. – Ignacio Vazquez-Abrams Jul 17 '11 at 20:55
Thanks a lot! It works now :) PS1="\033[0;37m[\033[1;33m\[\w\]\033[0;37m]\[\n\]\[\t\] \[${tRandColor}\]\[\u\]\033[0;37m@\[${tRandColor}\]\[${tBold}\]\[\h\]\[${tReset}‌​\] \$ – Runar Jul 18 '11 at 5:57

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.