4

I am using the gnome-terminal with bash, and when I have a command that should go over the line, it just stays on the same line. So instead of:

echo "abcdefghijklmnopqrstuvwxyz"

I would get

opqrstuvwxyz""abcdefghijklmn

Or something similar to that. However, if I press enter the command will still work. I believe it has something to do with my PS1 variable, but I don't know what is wrong with it. Here it is:

export PS1='\e[1;35m[\u:\w]\$\e[0;35m '
1
  • Confirmed. This PS1 causes the issue also in konsole (KDE). Jun 22, 2017 at 3:35

1 Answer 1

8

This seems somewhat related:

Wrapping the tput output in \[ \] is recommended by the Bash man page. This helps Bash ignore non-printable characters so that it correctly calculates the size of the prompt.

Source.

"The tput output" in your case looks like this: \e[1;35m, \e[0;35m (there are two separate fragments to wrap). They could be written as \033[1;35m and \033[0;35m as well. In general you need to wrap any non-printable sequence.

I modified your PS1:

export PS1='\[\e[1;35m\][\u:\w]\$\[\e[0;35m\] '

and it seems to work for me without the issue.