Server Fault is a question and answer site for system and network administrators. 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 have a custom bash prompt that colours my username, hostname and current working directory. The colours display correctly, however when I type a command line that needs to wrap, the terminal does not start a new line, and writes over the beginning of my command. This occurs on RHEL 4 and Debian.

This question details a similar problem on OS X; it would seem that this is an issue with incorrectly terminated control sequences, however I can't see what could be causing this, as I am using $(tput) codes everywhere, rather than hand crafting my codes. Snippet below - is anyone able to advise what I am doing wrong?

# Control codes

COL_RST=$(tput sgr0)  # Remove all colour formatting
COL_BRIGHT=$(tput bold) # Emphasise

# Foreground
COL_G=$(tput setaf 2) # Green
COL_Y=$(tput setaf 3) # Yello
COL_B=$(tput setaf 4) # Blue


# Set prompt

# Put it all together....
PS1="[$PROMPT]\$ "

export PS1
share|improve this question
up vote 8 down vote accepted

Wrap each of your color variables in escaped square brackets:




That tells Bash that these are to be considered zero-width.

This is exactly as described in the question you linked to. If you do the following command, you'll see that your variable contain similar character sequences to the "handcrafted" ones. Using tput only makes things portable to multiple $TERM types, it doesn't affect the length of the code sequences. It is that length that is throwing things off.

echo ${COL_USR} | hexdump -c
share|improve this answer
one tip: these [ ... ] sequences can't be nested. Now fixed in my bash prompt code at (shows git branch, host, etc, and red prompt for production servers). – RichVel Apr 8 '13 at 7:24

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.