stty设置终端参数

stty命令可以用来显示和设置终端参数。

-a 参数用来显示终端设置。

root@jumpstart:/ #>stty -a
speed 38400 baud;
rows = 24; columns = 80; ypixels = 0; xpixels = 0;
csdata ?
eucw 1:0:0:0, scrw 1:0:0:0
intr = ^c; quit = ^\; erase = ^?; kill = ^u;
eof = ^d; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^q; stop = ^s; susp = ^z; dsusp = ^y;
rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;
-parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk -crtscts -crtsxoff -parext
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
ixon -ixany -ixoff imaxbel
isig icanon -xcase echo echoe echok -echonl -noflsh
-tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten
opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3

其中:

intr 表示向当前正在运行的程序发送中断信号(ctrl+c)

quit 表示向当前正在运行的程序发送quit信号(ctrl+\)

erase 表示向后删除一个字符

kill 表示删除命令行的所有字符(ctrl+u)

eof 表示输入结束(ctrl+d)

start 表示重新开始屏幕输出(ctrl+q)

stop 表示停止向屏幕输出(ctrl+s)

susp 表示向程序发送terminal stop信号,暂时停止程序(ctrl+z)

werase 表示向后删除一个word (ctrl+w)

上述功能键设置可以通过stty命令修改。例如修改字符删除功能键方法如下。

当前设置:

root@jumpstart:/ #>stty -a | grep erase
intr = ^c; quit = ^\; erase = ^e; kill = ^u;
rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;

如果想把字符删除功能键定义为backspace键,则需要先知道backspace键是用什么字符表示的。方法是命令行下直接点击backspace键,然后点enter,如下:

root@jumpstart:/ #>^?
-bash:: command not found

上面说明^?表示backspace。

然后用stty命令将erase设置为backspace.

root@jumpstart:/ #>stty erase \^?

这样设置只在当前shell有效,如果需要永久生效,可以把stty erase ^?加到用户的.profile文件中。

posted @ 2012-02-07 13:15  生命的力量在于不顺从  阅读(1920)  评论(0编辑  收藏  举报