| 
 | 
从 shell 里访问终端模式
如果你正在使用 shell 而你又希望看到 termios 的设置,可以使用如下命令:[root@localhost ~]# stty -a 
speed 38400 baud; rows 24; columns 80; line = 0; 
intr = ^C; quit = ^\\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; 
swtch = M-^?; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; 
lnext = ^V; flush = ^O; min = 1; time = 0; 
-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts 
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff 
-iuclc ixany imaxbel iutf8 
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  
在上面,可以看到 EOF 字符对应着 Ctrl+D(eof = ^D) 并且使能了回显功能(echoe). 在做终端控制实验时,很容易把终端弄成一个非标准状态, 这就会造成使用起来很困难. 但是有几个办法可以使你摆脱(way out)这个困境:  
 
第一个方法,如果你的 stty 版本支持的话,使用以下命令: 
如果你把回车键和换行符(用来结束命令行)之间的映射关系搞乱了, 你可以先键入 stty sane, 然后按入 Ctrl+J(这个组合键对应着换行符) , 而不是按下回车. 
 
第二个方法是使用 stty -g 命令把当前的 stty 设置保存起来,在必要时再把原始值再读出来进行恢复.可以如下这么做:stty -g > save_stty 
.. 
<修改终端设置> 
.. 
stty $(cat save_stty)  上面,最后一条 stty 命令还是需要用 Ctrl+J 而不是回车键.在 shell 脚本程序里可以使用同样的技巧:save_stty = "$(stty -g)" 
<alter stty setting> 
stty $save_stty  
如果以上的这些招数都不管用了(if you're really stuck),第三个办法是打开一个不同的终端,使用 ps 命令找到你那个你弄得无法使用的 shell, 然后使用 kill HUP <process id> 强制把这个 shell 终止掉.因为 stty 参数总是在系统给出登录提示符前被重置,所以你能够在 stty 为初始值的情况下再一次正常的登录上机. |   
 
 
 
 |