Section 3.35. Changing a Terminal s Characteristics: stty


[Page 80 (continued)]

3.35. Changing a Terminal's Characteristics: stty

All terminals have the ability to process certain characters in a special manner; these characters are called metacharacters. Examples of metacharacters include the backspace character and the Control-C sequence, which is used to terminate programs. The default metacharacter settings may be overridden using the stty utility, described in Figure 3-46.


[Page 81]

Figure 3-46. Description of the stty command.

Utility: stty -a { option }* { metacharacterString <value>} *

The stty utility allows you to examine and set a terminal's characteristics. stty supports the modification of over one hundred different settings, so I've only listed the most common ones here. Consult man for more details. To list a terminal's current settings, use the -a option. To alter a particular setting, supply one or more of the following options:

OPTION

MEANING

-echo

Don't echo typed characters.

echo

Echo typed characters.

-raw

Enable the special meaning of metacharacters.

raw

Disable the special meaning of metacharacters.

-tostop

Allow background jobs to send output to the terminal.

tostop

Stop background jobs that try to send output to the terminal.

sane

Set the terminal characteristics to sensible default values.


You may also set the mappings of metacharacters by following the name of its corresponding string with its new value. A control character may be indicated by preceding the character with a ^ or by typing a \ followed by the actual control character itself. Here are the common metacharacter strings together with their meanings:

OPTION

MEANING

erase

Backspace one character.

kill

Erase all of the current line.

lnext

Don't treat the next character specially.

susp

Suspend the process for a future awakening.

intr

Terminate (interrupt) the foreground job with no core dump.

quit

Terminate the foreground job with a core dump.

stop

Stop/restart terminal output.

eof

End-of-input.



Here's an example of stty in action:

$ stty -a     ...display current terminal settings. speed 38400 baud; rows 35; columns 80; line = 233; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0; 
[Page 82]
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -ignbrk brkint ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke $ stty erase ^b ...set erase key to Control-B. $ stty erase ^h ...set erase key to Control-H $ _


Invoke stty from your shell's startup file if your favorite metacharacter mappings differ from the norm. stty is useful when building shells that need to turn keyboard echoing on and off; an example of such a script is included in Chapter 8, "The C Shell." Here's an example that uses stty to turn off keyboard echoing:

$ stty -echo     ...turn echoing off. $ stty echo      ...turn echoing back on again. $ _ 


Note that the last line of input (stty echo) would not ordinarily be seen due to the inhibition of echoing caused by the preceding line!

Now that you've seen how to set your terminal type and alter its settings, you can use full-screen editors like vim and emacs.




Linux for Programmers and Users
Linux for Programmers and Users
ISBN: 0131857487
EAN: 2147483647
Year: 2007
Pages: 339

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net