Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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:

  name@machine:~$ 

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\]\$
share|improve this question
2  
Tell me what echo $PS1 prints. –  cYrus Sep 8 '10 at 13:43

3 Answers 3

up vote 1 down vote accepted

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\]\$ '
share|improve this answer
    
Thanks cYrus, this fixed my problem perfectly. –  Andrew Larned Sep 8 '10 at 21:19

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.

share|improve this answer

When this happens:

  • Make sure your terminal window is wide enough.
  • Type command: reset
  • Press control+L.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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