[From]
https://www.zmrbk.com/post-2030.html
https://blog.csdn.net/suifengshiyu/article/details/40952771
我的理解是,如果出現如題所描述的問題,這是因為使用了不同的shell程序和對應的stty設置對應關系所綜合作用的結果。
這是/bin/sh里面stty -a命令輸出的信息:
$ stty -a speed 38400 baud; rows 43; columns 209; 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; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar 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 -flusho -extproc
這是/bin/bash里面stty -a命令輸出的信息,可以看到不同的字符映射:
pekkle@PPLinux:~$ stty -a speed 38400 baud; rows 43; columns 209; line = 0; intr = ^C; quit = ^\; erase = ^H; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0; -parenb -parodd -cmspar 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 -flusho -extproc
轉發以上兩篇文章,都是解決方法。簡單的方法是用/bin/bash代替/bin/sh,在ubuntu里是正常的。
linux下shell中使用上下鍵翻出歷史命名時出現^[[A^[[A^[[A^[[B^[[B的問題解決
今天在使用kali linux的時候,使用上下鍵想翻出歷史命令時,卻出現^[[A^[[A^[[A^[[B^[[B這種東東,而tab鍵補全命令的功能也無法使用。 最終發現是由於當前用戶使用的shell是/bin/sh的原因。 useradd的時候沒有指定用戶的shell類型,因此默認為/bin/sh。 1:查看當前用戶的shell類型命令: echo $SHELL 2:改變當前用戶登錄默認的shell:chsh -s /bin/bash username 或者使用usermod -s /bin/bash username命令 默認的shell改成/bin/bash之后正常了。 bash和sh的區別:http://hi.baidu.com/aaronike/item/08cfca8ab2ca145d850fabd3 sh其實是dbash的軟連接。
Linux使用退格鍵時出現^H解決方法
以前在linux下執行腳本不注意輸錯內容需要刪除時總是出現^H ,以前不知道真相的我沒辦法只有再重頭運行一次腳本,后來發現其實時有解決辦法的,所以記錄一下。 ^H不是H鍵的意思,是backspace。主要是當你的終端backspace有問題的時候才需要設置。 解決方法有兩種: 1、要使用回刪鍵(backspace)時,同時按住ctrl鍵 2、設定環境變量 在腳本的開頭或結尾 參數 stty erase ^H stty erase ^? 在bash下:$ stty erase ^? 或者把 stty erase ^? 添加到.bash_profile中。 在csh下:$ stty erase ^H 或者把 stty erase ^H 添加到.cshrc中