5

I'm working on a relatively new Linux Mint installation and I haven't noticed any significant issues until just now, I realised I couldn't use any command-line tools that interactively read user input. Instead of processing an enter key as I'd expect by consuming a line of input, it's printing the ^M character sequence to the terminal and continuing to prompt for input.
E.g. with git add -p:

Stage this hunk [y,n,q,a,d,j,J,g,/,e,?]? y^M

After a little more testing I realised that all shell read operations were doing this (in zsh and bash), and sh was entirely unusable.

zsh and bash:

$ read test
value^M^C
$

sh:

$ echo "test"^M^C
$ exit^M^M^M^C
$

I opened a new terminal and it seemed unaffected, so I'm not stuck here, but I'd love to know what happened to make this terminal behave as it is. I'll keep the broken one open for a while for testing if people have theories.

  • Ah drat, I got distracted while reading your first comment and copied the stty -icrnl instead of plain stty, so I think I've ruined my chances of investigating the exact state prior. However, I'm glad to have an understanding of how to both reproduce and fix the issue. Write them as an answer and I'll accept it. – Zoey Hewll Apr 17 '20 at 05:39

1 Answers1

6

This usually happens when a program which set the terminal to raw input mode died unexpectedly and wasn't able to restore the terminal settings to their prior values.

A simple stty sane should reset everything to normal.

As part of making the terminal "raw", the translation of Carriage-Return (^M, \r) to Line-Feed (^J, \n) is disabled by turning off the ICRNL flag in the c_iflag termios settings. This could also be done from the command line with stty -icrnl.

The command line of a shell like bash is usually not affected by this, because bash makes itself the terminal raw and does its own key translation (in order to provide nice line-editing capabilities as moving the insertion point left and right, command line history, etc) and only restores the default terminal settings upon running other commands.

  • The likely follow-on question is answered at https://unix.stackexchange.com/q/253271/5132 . – JdeBP Apr 17 '20 at 07:35