Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash invisible typing

Tags:

python

linux

bash

For a long time I'm facing with the fact bash in linux sometimes stops to print the symbols I'm entering. When I'm printing the text doesn't appear at the console window, but it actually enters. I can check this typing a special character like Ctrl-C or Enter and this would look like:

^\Quit (core dumped)
[kirill@localhost my]$ [kirill@localhost my]$ [kirill@localhost my]$ 

I can reproduce this with huge likelihood when I'm debugging my python script and manipulating with stdout handlers. During debug press Ctrl+| and in 4 of 5 cases I will see the issue above. Why does this happens and how to bring my console back to normal life?

like image 766
academica Avatar asked Sep 14 '25 22:09

academica


2 Answers

Why does this happens…

Good question.

Basically, terminals are way more complicated than they appear.

Certain values get interpreted by your terminal as command sequences that change its behaviour. During interactive use as an end user you don't usually have to worry about this. But sometimes these commands get triggered by accident, e.g. if you cat a binary file or when applications use other input modes and aren't properly shut down.

…and how to bring my console back to normal life?

Running stty sane often helps:

Reset all modes to reasonable values for interactive terminal use.

See also https://unix.stackexchange.com/a/79686/12606, which recommends following this command with tput rs1. I haven't used this last command myself, but will try it the next time stty sane on its own doesn't fix things.

like image 122
Chris Avatar answered Sep 17 '25 12:09

Chris


The terminal driver normally echoes the characters as they are typed. This however would be undesirable for an ncurses(3) terminal screen application, perhaps chosing an option from a screen menu, or in an editor like vi(1). Echo-ing characters would mess the screen up and confuse the typer.

So basically echo-ing is a terminal driver option, a terminal can be put into a raw mode, where the application is responsible for all input character processing.

Similarly, if control characters are sent to the terminal, it may well be put into a mode where it is NOT displaying characters as you expect. It's a common bug, if garbage is sent to terminals.

I should create your test text input in a file, redirect both stdout & stderr to a file and investigate with od(1), to see exactly what characters are output to check what's really going on.

like image 23
Rob11311 Avatar answered Sep 17 '25 12:09

Rob11311