Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 customized my bash with this in my bashrc

export PS1="\e[0;36m\h\e[m \e[0;33m\w/\e[m \e[0;31m\n\$ →\e[m  "

So I get something like this (with colors) :

Ahuri ~/Public/ 
$ →  

But I am having problems with long commands. When I write a very long command that is longer than a line it starts overwriting my first line

Example :

Ahuri ~/Public/ 
$ → ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If I continue to add "^" I get:

Ahuri ~/Public/ 

my "$ →" is overwritten, and then the whole line gets overwritten.

share|improve this question
up vote 8 down vote accepted

There is no issue with the \n. This is yet again the old escape sequence length problem: \e[0m and similar do not contribute to the actual length of the prompt, so you have to enclose them in \[..\] to indicate this to the interpreter:

PS1="\[\e[0;36m\]\h\[\e[m\] \[\e[0;33m\]\w/\[\e[m\]\n \[\e[0;31m\]\$ →\[\e[m\]  "
share|improve this answer
This worked just fine. Thank you very much – Ahuri3 Apr 3 '13 at 12:33

Use $PROMPT_COMMAND to display the additional line so you have no \n in $PS1.

share|improve this answer
Could you please provide an example of how this is implemented? – Chris K Jan 13 '14 at 20:37

A simpler option is to use the tput sequences:

export PS1='\[$(tput setaf 4)\]\h\[$(tput sgr0)\] \[$(tput setaf 3)\]\w/\[$(tput sgr0)\]\n\[$(tput setaf 1)\]\$ →\[$(tput sgr0)\] '
share|improve this answer
Are you sure? tput not seems to add anything special to solve the length calculation: pastebin.com/u28RTT5t – manatwork Apr 3 '13 at 12:37

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.