When I try to colorize the bash prompt like this:

export PS1="\e[0;31m[\u@\h \W]\$ \e[m "

it breaks the carriage return (instead of going to a new line when line is full, it starts in the same line and erases the input text).

If I remove the color sequence it works fine.
I use Ubuntu 11.10 and terminal (guake has the same bug too).

link|improve this question
Strange. It works w/o any problem on RedHat 5 and Mac OS X – Matteo Dec 12 '11 at 20:08
possible duplicate of PS1 problem, cmd is looping – grawity Dec 12 '11 at 20:10
feedback

1 Answer

up vote 5 down vote accepted

You must wrap all escape sequences between \[ and \] in order for 'readline' to correctly calculate the prompt's visible length. Without them, 'readline' thinks the prompt is longer than it is, and doesn't know when the text reaches the margin.

PS1="\[\e[;31m\][\u@\h \W]\$ \[\e[m\]"
link|improve this answer
Thx you, it what I expect. – Abonec Dec 12 '11 at 20:33
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.