3

I know there are many related questions, however I couldn't find any other way to get help on this problem:

On my CentOS VM I made a custom script for my bash prompt in /etc/profile.d/custom.sh

PS1="\n\e[0;97m\][\D{%d%m%y-%H%M}][\u@\h \W] \n\e[m\]\$ "
export PS1

My bash now looks like this:

custom bash prompt

However If I type a long command and if I want to get the cursor on the first position using CTRL-A this is what happens:

Typed something long. I want to change something at the beginning of the line so I will press CTRL-A to get the cursor at the first position:

typing a long command

After pressing CTRL-A:

enter image description here

Now if I try to delete the whole line with DEL or BACKSPACE this is the end result?

enter image description here

No matter how much I try to delete those 4 chars they always stay until I hit the ENTER key. Those last 4 chars are always displayed but it is like they don't exist.. I am free to type commands and they will be ignored:

enter image description here

At the last picture I successfully executed cd /var command and now the bash is like it is intended.

Any thoughts?

Spirit
  • 225

1 Answers1

6

You need a \[ before each \e:

PS1="\n\[\e[0;97m\][\D{%d%m%y-%H%M}][\u@\h \W] \n\[\e[0m\]\$ "
yaegashi
  • 12,326
  • \[\e is the first one and \[\e is near the end of that line? I don't see anywhere else.. – Spirit Jun 06 '15 at 11:52
  • @Spirit You need to use \[ and \] in pairs. Your original PS1 had 2 unmatched \]s. Find the difference carefully. – yaegashi Jun 06 '15 at 12:08