I'm using Ubuntu (10.04) with bash, and am running into an odd issue. After I use the up arrow to scroll back through my history of commands, and get back to one of the longer commands (i.e., one with enough characters to wrap on the screen), but then continue to scroll either forward or backward, the first 8 or 9 characters of that long command show up on my entry line.

These characters don't have any impact on whatever command I eventually enter, but it's occasionally hard to figure out what I'm trying to type.

It looks something like this first:


Then becomes this:

  name@machine:~$ scp -i /h

after scrolling back to one of my long scp commands. If I then enter a command, like so:

  name@machine:~$ scp -i /hls -l

it executes the command: ls -l

Edited to add the value of PS1 in my ~/.bashrc

  PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\033[31;40m\]$(__git_ps1 "[%s]")\[\033[00m\]\$ '

Edited again to add the value of echo $PS1

  \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\033[31;40m\]$(__git_ps1 "[%s]")\[\033[00m\]\$
  • 2
    Tell me what echo $PS1 prints.
    – cYrus
    Sep 8 '10 at 13:43

You miss a \[ (the one after \w), try this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[31;40m\]$(__git_ps1 "[%s]")\[\033[00m\]\$ '

The value of your PS1 variable contains some non-printing characters such as sequences to set colors. They need to be wrapped in \[ and \] so they're not counted when Bash calculates where to display things and move them when you do things like scrolling through previous commands. If you show your PS1 I can be more specific.


When this happens:

  • Make sure your terminal window is wide enough.
  • Type command: reset
  • Press control+L.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.