Shell自定義快捷鍵方法詳解

2020-07-16 10:04:39
首先,我們要學會檢視 Shell 中已有快捷鍵的方法,如下所示:

[[email protected] ~]# stty -a
#查詢所有的快捷鍵
speed 38400 baud; rows 21; columns 1.04; line = 0;
intr = ^C; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
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 -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc —ixany -imaxbel
-iutf8
opost -Olcuc -ocrnl onlcr -onocr -Onlret -ofill -ofdel nlO crO tabO bsO vtO ff0 isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke


"-a"選項用於査詢系統中所有可用的快捷鍵,可以看到,"Ctrl+C"用於強制中止,"Ctrl+D"用於中止輸入。那麼,這些快捷鍵可以更改嗎?

當然可以,只需執行以下命令即可:

[[email protected] ~] # stty 關鍵字 快捷鍵
例如:
[root01ocalhost ~]# stty intr ^p
#定義Ctrl +P快提鍵為強制中止,"^"字元只需手工輸入即可
[[email protected] ~】# stty -a
speed 38400 baud; rows 21; columns 104; line = 0;
intr = ^P; quit = ^; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 1; time = 0;
#強制中止的快提鍵變成了Ctrl+P