Bash – The effect of `stty –file= ` is only temporary for consoles in bash. Why

bashsttytty

Open two consoles / X terminals. From one, which is attached to say /dev/tty1 (Linux console) or /dev/pts/0 (X terminal), run $ stty -echo. (Now echoing to keyboad is turned off.) Then from the other, run $ stty --file=/dev/tty1 echo.

Now type something in the first terminal. It echoes, ok, the last stty took effect. But once you press the enter key, It reverts to -echo state. Why is this? Is a permanent change possible?

This does not apply to some combinations of stty flags, at least not for 'echo / -echo'. When `$ stty –file= ' is run from the same terminal, it affects permanently.

N.B. Zsh has its own policy for stty. See this question

EDIT: In the first post, I failed to report that this happens in bash, but not in dash. The mention to zsh case was also added.

Best Answer

Your shell does this, to help you edit command-lines.

bash's readline library saves/restores terminal modes. You can see this in the rl_prep_terminal and rl_deprep_terminal functions, called indirectly from edit_and_execute_command.

Related Question