美文网首页
使用stty修改终端设置

使用stty修改终端设置

作者: Nothing_655f | 来源:发表于2020-09-03 11:12 被阅读0次

    stty 用法

    在linux/unix平台上的 sqlplus中,如果输错了字符,要想删除,习惯性的按下backspace键后,发现非但没有删除想要删掉的字符,还多出了两个字符^H。当然,我们 可以同时按下ctrl+backspace键来删除,但对于习惯了用backspace来删除的用户,这样很不爽。这可以通过修改tty终端的设置来实现 backspace删除功能。通过使用stty命令,就可以查看或者修改终端的按键设置。
    例如,设置backspace为删除键:

    [oracle10g@linux]$ stty erase ^h
    

    如果要改回使用ctrl+backspace为删除键

    [oracle10g@linux]$ stty erase ^?
    

    [转载注]在设置backspace时,最好先在shell提示符下按一下backspace键试一下,如果显示^h就设置成stty erase ^h, 如果^?就用stty erease ^?
    如果需要重启后自动设置终端,可以将上述命令加入到profile中。
    可以通过stty -a命令来查看所有的终端设置。下面是在linux下执行的输出:

    [oracle10g@linux]$ stty -a
    speed 38400 baud; rows 66; columns 132; line = 0;
    intr = ^C; quit = ^\; erase = ^H; 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;
    -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
    

    其中:
    • eof : 输入结束
    • erase : 向后删除字符,
    • intr : 中断当前程序
    • kill : 删除整条命令
    • quit :退出当前程序
    • start : 启动屏幕输出
    • stop :停止屏幕输出;
    • susp : terminal stop当前程序。


    下面是我的.bashrc下面的相关设置

    # Terminal-related commands, tput, tset, stty, etc should not be
    # executed by vuelogin or dtlogin. These login environments set VUE # andVUE # andDT accordingly.
    #
    if [ ! "VUE"−a!"VUE"−a!"DT" ]; then
      # Terminal specific commands...
      #tty -s && stty intr ^c susp ^z kill ^X erase ^h quit ^\\ eof ^d
      tty -s && stty intr ^c susp ^z kill ^X erase ^? quit ^\\ eof ^d
    

    部分其他用法:

    1. 打印终端行数和列数

    stty size

    2,在命令行下禁止输出小写

    stty olcuc #开启
    stty -olcuc#恢复

    3,打印出终端的行数和列数

    stty size

    4,改变ctrl+D的方法:

    stty eof "string"
    系统默认是ctrl+D来表示文件的结束,而通过这种方法,可以改变!

    5,屏蔽显示

    stty -echo #禁止回显
    stty echo #打开回显
    测试方法:
    stty -echo;read;stty echo;read

    6,忽略回车符

    stty igncr #开启
    stty -igncr#恢复

    7 .利用它设置我们的串口打印操作信息。

    stty -F /dev/ttyS0 speed 115200 cs8 -parenb -cstopb -echo

    解释:通过stty设置/dev/ttyS0串口, 波特率为115200 ,数据位cs8,奇偶校验位-parenb,停止位-cstopb,同时-echo禁止终端回显。

    来自 https://www.cnblogs.com/the-tops/p/5621207.html

    相关文章

      网友评论

          本文标题:使用stty修改终端设置

          本文链接:https://www.haomeiwen.com/subject/jiunsktx.html