Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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'm colorizing parts of my bash prompt using ANSI escape sequences. This works great, until the command I'm currently typing in is long enough that it has to wrap. Instead of the rest of the command displaying on the next line, it wraps back to column 1 of the current line, overwriting the beginning of the prompt.

I get that behavior with this prompt:

export PS1="[\u][\033[0;32;40mdemo \033[0;33;40m1.5.40.b\033[0;37;40m] \w> \033[0m"

but it works correctly with the same prompt, ANSI sequences remove:

export PS1="[\u][demo 1.5.40.b] \w> "

I'm connecting using the current version of Putty, with default Putty settings. The OS is Ubuntu 8.10.

share|improve this question
up vote 1 down vote accepted

It must be something in there because the following string from the bash documentation does not exhibit the same behavior:

PS1="\[\033[1;34m\][\$(date +%H%M)][\u@\h:\w]$\[\033[0m\] "

Haven't figured out what it is yet, but their works and yours doesn't...

EDIT: Try:

PS1="[\u][\[\033[1;32m\]\[\033[1;40m\]demo \[\033[1;33m\]\[\033[1;40m\]1.5.40.b\[\033[0;37m\]] \w> \[\033[0m\] "
share|improve this answer
That did it. The reason, it turns out, is that bash needs to be told "the following characters are non-printable" so it doesn't become confused over the length of the prompt. This is done by enclosing non-printable characters in \[ and \]. See – Eric J. Apr 12 '10 at 20:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .