I added the following to my ~/.bashrc:

export PS1="\e[0;35m[\u@\h \W]\$ \e[m "
echo -e "\e[0;35mYOU ARE ON THE LIVE SERVER !!\e[0m"

sadly, now, every time I paste something long into bash it goes squiffy and ghost tab characters appears all over the screen, and lines eat each other, does anyone know why?

  • PS: it also happens when I up arrow into anything long
    – Mr Heelis
    May 2, 2017 at 17:00

2 Answers 2


I also had in the past the problem of ANSI colour codes messing up with command line navigation; you need to put the ANSI codes around \[ \] in order for the command shell to know how (not) to take them into account as part of the input string.

As in:

export PS1="\[\e[0;35m\][\u@\h \W]\$\[\e[m\] "
echo -e "\[\e[0;35m\]YOU ARE ON THE LIVE SERVER !!\[\e[0m\]"

Some explanation as to why the shell needs \[ and \]: To draw the prompt in the correct positions in the character matrix of a terminal the shell needs to know the correct length of the prompt string which is the amount of printable characters, i. e. not control characters or character sequences.

However, the shell doesn't know which character sequences the terminal considers printable. Therefore one needs to provide hints to the shell to distinguish between printable and non-printable sequences, which is the purpose of \[ and \].

  • 1
    Correction: You need to put \[ \] around the ANSI codes, not just [ ] (and not the ANSI codes around the brackets).
    – jwodder
    May 2, 2017 at 21:03
  • Indeed, 2nd time called to attention...amended the text, thanks. May 2, 2017 at 21:04

I've kind of fixed it I used this website http://bashrcgenerator.com/ and did it the long handed way, it's a LOT longer but if you double click the elements you can colour them and it DOES work

I ended up with

   export PS1="\[\033[38;5;129m\][\u@\h\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]\[\033[38;5;129m\]~]\\$\[$(tput sgr0)\]\[\033[38;5;15m\] \[$(tput sgr0)\]"

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