Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

bash - What does "stty raw -echo" do on OS X

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...