What does “stty raw -echo” do on OS X

做~自己de王妃 提交于 2019-11-27 17:21:20

问题


When I try: $ stty raw -echo on my Terminal (Bash on OS X 10.6). It does stringe things and it's like the terminal hang there. Then I lookup the manual:

stty — set the options for a terminal device interface

raw (-raw)

If set, change the modes of the terminal so that no input or
output processing is performed. If unset, change the modes of the terminal to some reasonable state that performs input and output processing. Note that since the terminal driver no longer has a single RAW bit, it is not possible to intuit what flags were set prior to setting raw. This means that unsetting raw may not put back all the setting that were previously in effect. To set the terminal into a raw state and then accurately restore it, the following shell code is recommended:

save_state=$(stty -g)
stty raw
...
stty "$save_state"              

echo (-echo)

Echo back (do not echo back) every character typed.

So it's supposed to turn the Terminal in raw mode then return what I type in as is? Could someone please explain what does this command do? And what is the difference when an argument has dash, e.g. raw and -raw? Are they mean the samething? Is there any resource I could learn this?


回答1:


Firstly, the dash means "disable" a setting. So this enables echoing:

stty echo

This disables it:

stty -echo

When you disable it, your typing is not echoed back to you, which is why it seems as if the terminal is hanging. Try stty -echo then type ls and press return - you will still see the output of ls.

The raw setting means that the input and output is not processed, just sent straight through. Processing can be things like ignoring certain characters, translating characters into other characters, allowing interrupt signals etc. So with stty raw you can't hit Ctrl-C to end a process, for example.



来源:https://stackoverflow.com/questions/22832933/what-does-stty-raw-echo-do-on-os-x

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!