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.

  • 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
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.

  • Thanks. So it's specific to bash. For the record: it's done in bashline.c. – teika kazura Feb 21 '17 at 6:38
  • well yes - the last link points there, but the function-name seemed more useful. – Thomas Dickey Feb 21 '17 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.