3

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.

teika kazura
  • 322
  • 2
  • 16
  • 1
    Your shell is probably do that - resetting terminal modes to allow you to edit command-lines. With more information, this would be a duplicate. – Thomas Dickey Feb 19 '17 at 11:04
  • Oops, sorry, as you said, it only happens in bash, not in dash. But I can't locate the culprit. Nowhere in the files read at bash startup, there's no `stty` invocation. PS1 does not matter, right? Any hint? – teika kazura Feb 19 '17 at 13:15

1 Answers1

2

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.

Thomas Dickey
  • 75,040
  • 9
  • 171
  • 268