I have an Ubuntu 12.04 system where I, at reboot, login a root. This morning I did the things I had to and thought about running

apt-get -y upgrade

I started typing this but before pressing Enter I looked at the screen to check for mistyping things, and did see the cursor (blinking underscore) a few spaces after the final e like this (without the actual blinking):

apt-get -y upgrade    _

I definately did not type any spaces after the final e. After that I did just press Enter and apt-get ran fine.

I have often seen this happen before and would like to know what might cause this, in order to prevent it from happening again. Alternatively some way to reset this would also be acceptable.

Some details:

  • I tried stty sane, that did not change anything.
  • Before the apt-get command I did run a mount and w. The change happened between starting to type apt... and the final e
  • This was on tty2. When I logged out the cursor at the login: prompt was not at the position, but a few positions off on as well.
  • Switching to tty1, where I was not logged in, showed the cursor at the wrong position as well.
  • I switched back to the GUI (Alt+F7) and back to tty2 and the cursor was still off.
  • After looking at tty2 a minute or two later (while writing this Q and wanting to check something) the login: prompt was still there but now the cursor was at the right position.
  • I tried to recreate the problem by issuing the same commands (but with different amounts of time between them as before, now directly after each other) and could not get the cursor to bulge from the normal position.
  • echo $TERM gives linux
  • echo $PS1 gives ${debian_chroot:+($debian_chroot)}\u@\h:\w\$

This would not bother me so much, but it has happened quite often. When just typing commands it is not such a problem, but it completely confuses me, when it happened and I want to edit some previous command (bash), as then the insertion point is a few positions left from the blinking cursor.

How can I reset the cursor to the right position when this happens? Or preferably: how to prevent this from happening?

  • Does your prompt correctly protect any control sequences with \[…\]? Is TERM correct? – Gilles Feb 10 '14 at 8:42
  • @gilles I don't have any \[..\] in the prompt. And $TERM is linux ( I updated the details list with these two). – Timo Feb 10 '14 at 9:07
  • Your $TERM and $PS1 are the same as mine. Did you type any commands longer than the tty width of 80 characters and/or delete back to the previous line? – Harold Feb 10 '14 at 9:13
  • @Harold I tried with a long line until I got to the next and Backspaced back to the previous. That did not cause it (and I sure did not do that the last time the cursor 'moved'. – Timo Feb 10 '14 at 9:18
  • Maybe you need \[…\], that's the point. Is your prompt in color? Copy-paste your PS1 assignment, or the output of printf '%s\n' $PS1 | cat -v – Gilles Feb 10 '14 at 10:34

Your Answer

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

Browse other questions tagged or ask your own question.