bash “stty raw -echo”在 OS X 上有什么作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22832933/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does "stty raw -echo" do on OS X
提问by Juanito Fatas
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 raw -echo
在我的终端上(OS X 10.6 上的 Bash)。它会做一些事情,就像终端挂在那里一样。然后我查找手册:
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.
stty — 设置终端设备接口的选项
原始(-原始)
如果设置,则更改终端的模式,以便不执行输入或
输出处理。如果未设置,请将终端的模式更改为执行输入和输出处理的某种合理状态。请注意,由于终端驱动程序不再具有单个 RAW 位,因此无法直观地知道在设置 raw 之前设置了哪些标志。这意味着取消原始设置可能不会恢复以前有效的所有设置。要将终端设置为原始状态,然后准确还原,建议使用以下 shell 代码:save_state=$(stty -g) stty raw ... stty "$save_state"
回声(-回声)
回显(不回显)输入的每个字符。
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?
所以它应该将终端转为原始模式,然后按原样返回我输入的内容?有人可以解释一下这个命令的作用吗?当参数有破折号时有什么区别,例如raw
和-raw
?他们的意思是一样的吗?有什么资源我可以学习这个吗?
回答by Josh Jolly
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
.
当您禁用它时,您的输入不会回显给您,这就是为什么终端似乎挂起的原因。尝试stty -echo
然后键入ls
并按回车键 - 您仍然会看到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.
该raw
设置表示不处理输入和输出,直接发送。处理可以是忽略某些字符、将字符转换为其他字符、允许中断信号等。因此,例如,stty raw
您不能按 Ctrl-C 来结束进程。