BASH, PS1 and the long commands

Had a strange behavior in my bash while browsing the command history. I'm always traveling in time with the <Up> arrow in my bash, but when a long command (longer than $COLUMNS) is being loaded, the prompt ($PS1) dissapears and it starts to behave as hell:

After some reserach here and there, as usual, StackOverflow gave me the answer: the unenclosed non-printable character sequences:

In my case it was exactly like that:

export PS1="\033[1;30m\]» \[\e[0;33m\]mbp\033[1;30m\]╺─╸\[\033[1;30m\][\[\033[0m\]\W\[\033[1;30m\]]\[\033[1;34m\]:\[\033[0m\] "
export PS1="\[\033[1;30m\]» \[\e[0;33m\]mbp\[\033[1;30m\]╺─╸\[\033[1;30m\][\[\033[0m\]\W\[\033[1;30m\]]\[\033[1;34m\]:\[\033[0m\] "

Could you spot the difference?. Please ensure all your non-printable sequences are enclosed in \[ and \] in your prompt before complain about bash doing weird things.

About the author

Óscar
has doubledaddy super powers, father of Hugo and Nico, husband of Marta, *nix user, Djangonaut and open source passionate.
blog comments powered by Disqus