Linux – Wrong linebreak on SSH connection when scrolling back in bash


I have a Bash Terminal via a SSH connection in GNOME terminal.
Server is Debian Linux, Client is Ubuntu Linux.

The output of long lines is displayed well, but when I use the UP-key to scroll in the bash history, the output goes only 80 characters, is then broken and starts in the same line again.

It should look like this:

server01:/usr/local/bin# very-long-command parameter1 paramter2 paramter3

But it looks similar like this:

parameter3 usr/local/bin# very-long-command parameter1 paramter2 

Best Answer

This can happen when you have escape sequences (as generated by tput) in your prompt that are not surrounded by \[ and \]. Those backslashed brackets tell Bash that the escape sequences do not take up any horizontal space on the screen. Without them around the escape sequences, Bash counts each byte of the escape sequence as a visible character, which messes up previously displayed commands as you move back and forth through command history.