18

In my interactive bash shell run in lxterminal's window, I don't know what I have messed up.

Typing Return key doesn't start a new line, but Ctrl-C will.

$ ^C
$ $ $ $ $ ^C
$ ^C
$ $ $ $ $ $ $ 

When I type a command, although hitting Return key will execute it, the typed command is not visible.

Before that happened, I was running some command sudo lsof ... | less (or sudo netstat ... | less), and there seemed no output, so I hit ctrl-c and/or q multiple times in an arbitrary order. When I finally got out of less, that problem with bash happened.

Did I accidentally redirect the stdout of the shell somewhere else?

Is there some way to fix the problem without closing my shell?

3 Answers 3

33

I think your terminal may be stuck in a “funny” mode. You probably can reset it with the /usr/bin/reset command, that normally comes with the ncurses library.

6
  • 1
    Thanks. Do you know what can cause the problems (which reset can solve)?
    – Tim
    Commented Jan 6, 2019 at 14:20
  • 7
    Commands like less use the terminal in a different way, that most commands. To do what they do, they send control codes, and escape sequences to the terminal to change its mode. The should but it back, when they are done, but if you kill less with no opportunity for it to run the reset code, then you end up where you are. Ctrl-C should send a sig int, this should be caught, and the reset code run, before exit. Sending sig kill, or bugs in less could cause the problem. Commented Jan 6, 2019 at 14:58
  • 2
    Note that sometimes the terminal is stuck so that the RETURN key doesn't work as expected. In this case control-J (^J) may work; eg ^Jreset^J Commented Jan 8, 2019 at 1:37
  • Thanks @StephenHarris ! Could you add an answer or add something about ^J to this answer? People who don't think of reset might not know about ^J (as was my case)
    – KevinG
    Commented Jun 6, 2019 at 3:52
  • Thanks @StephenHarris. You should add this as an answer. Commented Aug 11, 2020 at 12:36
15

If reset (proposed in another answer) does not work, try:

stty sane

maybe followed by

tput rs1

I have the following alias defined (guess I picked it up somewhere on stackoverflow):

alias   fixtty='reset; stty sane; tput rs1; clear; echo -e "\033c"'
1
  • In my .profile I have export sttyparms=$(stty -g) and then an alias sane=stty $sttyparms which ensures things like stty erase are restored to my values (hold over from old DEC Ultrix days where the default need not match the VT terminal setting!) Commented Jan 8, 2019 at 1:40
9

As other answers suggest, simplest fix is just to run reset.

As to the cause though? This usually happens when you cat (or otherwise output) a binary file or data to your terminal.

Text is just text, and is not treated specially by the terminal, but there are also some special characters which aren't text, and are used to do things like move the cursor, clear the screen, change colour, stop echoing output, etc.

When you output binary data (rather than text), the terminal will see these special control characters and try to interpret them as they come through. You may notice the screen clears, flashes, or jumps around - this is all due to these control characters being honoured. You can experiment by running head /dev/urandom in a new terminal to see what I mean.

Most of the time, if your terminal is behaving weird in anyway, just running reset will fix it, by simply echoing all the special characters necessary to set the terminal into the basic default mode - e.g. there is a stop echoing input code and also a start echoing input code. The binary data has randomly included the former, which is why you can't see what your typing, and reset will include the latter (among others), which will fix it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .