Linux Ubuntu stty 使用

mac2022-06-30  61

stty(set tty)命令用于显示和修改当前注册的终端的属性。 该命令是一个用来改变并打印终端行设置的常用命令。

stty -a #将所有选项设置的当前状态写到标准输出中 old_stty_settings=stty -g #保存当前设置 stty “$old_stty_settings” #恢复当前设置 stty -echo #禁止回显,当您在键盘上输入时,并不出现在屏幕上 stty echo #打开回显 stty raw #设置原始输入 stty -raw #关闭原始输入 stty igncr #开启忽略回车符 stty -igncr#关闭忽略回车符 stty iuclc #开启在命令行下,禁止输出大写的方法 stty -iuclc #恢复在命令行下,禁止输出大写的方法 stty olcuc #开启在命令行下禁止输出小写 stty -olcuc#恢复在命令行下禁止输出小写 stty size #打印出终端的行数和列数

stty -a #将所有选项设置的当前状态写到标准输出中

stty -a

输出

speed 38400 baud; rows 31; columns 60; 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

stty -echo #禁止回显,当您在键盘上输入时,并不出现在屏幕上 输入命令也不会显示在屏幕上

stty -echo

stty echo #打开回显 从键盘输入的命令会显示在屏幕上

stty echo

stty raw #设置原始输入 打开以后的效果就是排版上会有些不同

stty raw

例如在运行下面的命令 会这样 排版不清楚,这就是原始输入被打开了

stty -a speed 38400 baud; rows 32; columns 122; 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

stty -raw #关闭原始输入

stty -raw

在运行上面的命令

stty -a speed 38400 baud; rows 31; columns 60; 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

输出会经过排版了

stty igncr #开启忽略回车符

stty igncr

要是在终端shell 输入这个命令 终端就不能就收回车了 那么怎么执行命令呢 这代码只能在 shell 脚本文件中运行吗

stty -igncr#关闭忽略回车符

stty -igncr

运行 忽略回车的命令后,不知道怎么运行下面的命令… 只能重启shell stty iuclc #开启在命令行下,禁止输出大写的方法

stty iuclc

这样在shell 终端中就输入不了大写 stty -iuclc #恢复在命令行下,禁止输出大写的方法

stty -iuclc

执行后 就可在终端再次输入大写字母 stty olcuc #开启在命令行下禁止输出小写

stty olcuc

禁止小写 ,要在shell终端中运行这个代码,估计又要重启shell了… 这样的代码只能在shell脚本中用吧

stty -olcuc#恢复在命令行下禁止输出小写

stty -olcuc

stty size 打印出终端行列

stty size 31 60

下面是shell stty -echo 这个命令适合输入密码

#!/bin/sh stty -echo echo -n "Please Put in your password:" read password stty echo echo -e "\nYour password is: $password"

转载于:https://www.cnblogs.com/vercont/p/10210158.html

相关资源:UbuntuLinux操作系统
最新回复(0)