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

In my bashrc file I have my prompt set as follows:


The prompt therefore is simply a green "i:". When I work in my shell and I scroll up in the history my command line messes up. Consider the following:

i: shell_command_one
i: shell_command_two
i: shell_command_three

Now when I go up in my history the line might look something like this:

i: shell_comshell_command_two

If I hit enter on that it executes shell_command_two. (Notice how the shell_com is just junk characters on the terminal.

I suspect it might have something to do with the color characters being non-printing. Does anyone know how to fix this in bash?

p.s. I'm not sure if this is better posted on superuser but I thought it might be best here since its about bash scripting.

share|improve this question

migrated from Feb 19 '13 at 8:31

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

up vote 2 down vote accepted

It appears you have a malformed CSI color code. Try this in your .bashrc file:

PS1="${TC_GRE}i: "  
share|improve this answer
Worked with a small fix... TC_GRE="[\033[0;32;40m]" TC_RESET="[\033[0;0m]" PS1="${TC_GRE}i:${TC_RESET}" I still wanted to reset the foreground color so it wasn't always green. Thanks! – David Mokon Bond Feb 18 '13 at 18:46
It's not so much a malformed color code, as you were inserting characters into the prompt which did not move the cursor when printed. The \[...\] pair wraps those characters so that bash doesn't get confused about how much space on-screen the prompt occupies. – chepner Feb 18 '13 at 19:39
Thanks, that helps explain the behavior better. – David Mokon Bond Feb 18 '13 at 23:38

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.