This question already has an answer here:

Good Morning-

I'm trying to use tput outputs in my $PS1 to set the background color to red in the event I'm on a production server:

if [[ `hostname -s` = prod-db ]]; then
  export PS1="${TITLEBAR}`tput setab 1`[\u@\h \W \$ORACLE_SID]\$`tput setab 0` "
  export PS1="${TITLEBAR}[\u@\h \W \$ORACLE_SID]\$ "

However, I'm finding that when I'm on prod-db, the line wrapping is quite messed up; it seems fixed to a certain number of characters and does that fun thing where modifying a command that goes too long goes up a line without redrawing the screen as though the terminal is entirely messed up.

When the background color is not set, none of those issues occur... I'm happy.

PS1 is being set to [\e]0;\u@\h echo $ORACLE_SID\a]^[[41m[\u@\h \W $ORACLE_SID]$^[[40m with colors and to [\e]0;\u@\h echo $ORACLE_SID\a][\u@\h \W $ORACLE_SID]$ without colors.

The only difference being the escape characters being set to set the colors, I don't see what would be breaking the line wrapping.

I'm running GNU bash 4.1.2.

Why does the introduction of the color escape codes cause line wrapping to break, and what is the proper way to resolve the issue?

marked as duplicate by Gilles, slm, rahmu, Anthon, Rahul Patil Sep 18 '13 at 5:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Thank you for pointing me to the similar issue with the same fix! – Rob Sep 18 '13 at 18:57