When I write a long command and the line of text gets to end of terminal, it continues at beginning the same line (as if it was "overwriting it), and if I hit home it doesn't really go to the beginning of the line.

I've found this question, this other, etc., and I now it is related with the colors and things I want it to display... and I am so sorry to open another post, but I tried to edit the line myself but I can't really get it ok. Can yo guys give me some help?

Here is the extract from my .bashrc:

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\][\u@debian]\[\033[01;34m\][\033[01;34m\]\w\]]\033[01;34m\]\$\033[00m\] '

To clarify it, I want the prompt to be:


  • Meaning, username@debian between brackets [\u@debian], in green color

*Yes, I want it to display "debian", not usual \h

  • Working directory also between its brackets [\w], in blue color
  • The $ of normal user
  • And the text I type to be displayed in white colour.
  • I don't care about root user's prompt.

Thanks for the help, and again, sorry to open another post for this...

Edit: I tried to rewrite it after slowly reading this full tutorial. But wasn't able to make it work. Now it doesn't "overwrite" the first line, but on the second, after a few characters, overwrites that second line for just a few characters, then continues ok. But with this new PS1, if I hit the UP arrow on the keyboard to previous commands, it gets really funky.

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[[\]\u\[@debian]\]\[\033[01;34m\]\[[\]\w\[]\]\[\033[01;34m\]\$\[\033[00m\] '

If I didn't get wrong the tutorial, it is supposed to be:

  • \[ Begin a sequence of non-printing characters.
  • \] end the sequence of non-printing characters.
  • \033[XXm color, that needed to be between the start and end of non-printing characters, so, for example, for color blue (34) it should be: \[\033[34m\]

So, in my mind, it should work now, but it doesn't. Clearly I'm not seeing it right -.-

1 Answer 1


Looks like a typo here:


That [ ought to be \[.

The \[...\] markers tell Bash that those portions of the string don't contribute to column count.

  • I seem to lose the [ before the working directory, meaning it shows [user@debian] ~] $ (I use spaces here so it's easier to read, but the characters are, of course, all next to each other) Here is a screenshot
    – PolGZ
    Feb 3, 2021 at 13:50
  • Perhaps you wanted both \[ and [, then, each in the appropriate place. [ where you want a literal [, and \[ around each of the control sequences: [\[\033[01;34m\]\w\[\033[00m\]]? You might find it easier to define some variables, e.g. green='\['"$(tput setaf 2)"'\]' etc. Feb 3, 2021 at 16:27
  • I tried the suggested string [\[\033[01;34m\]\w\[\033[00m\]], but it doesn't seem to work. I've edited the main post with another try starting from scratch. Maybe you can help from that now
    – PolGZ
    Feb 3, 2021 at 19:47
  • I think you're getting really confused. For example \[[\] is completely broken - you've told Bash that [ doesn't take any screen space. There's one simple rule - use \[..\] around sequences that don't advance the cursor, and nowhere else. Feb 3, 2021 at 21:07
  • THANK YOU so much! I completely misunderstood everything!! \[...\] should have been only for the colors! I LOVE YOU SO MUCH!
    – PolGZ
    Feb 3, 2021 at 22:01

You must log in to answer this question.

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