UNPKG

1.47 kBMarkdownView Raw
1stty
2===
3
4修改终端命令行的相关设置
5
6## 补充说明
7
8**stty命令** 修改终端命令行的相关设置。
9
10### 语法
11
12```shell
13stty(选项)(参数)
14```
15
16### 选项
17
18```shell
19-a:以容易阅读的方式打印当前的所有配置;
20-g:以stty可读方式打印当前的所有配置。
21```
22
23### 参数
24
25终端设置:指定终端命令行的设置选项。
26
27### 实例
28
29 **在命令行下,禁止输出大写的方法:**
30
31```shell
32stty iuclc #开启
33stty -iuclc #恢复
34```
35
36 **在命令行下禁止输出小写:**
37
38```shell
39stty olcuc #开启
40stty -olcuc #恢复
41```
42
43 **打印出终端的行数和列数:**
44
45```shell
46stty size
47```
48
49 **改变Ctrl+D的方法:**
50
51```shell
52stty eof "string"
53```
54
55系统默认是Ctrl+D来表示文件的结束,而通过这种方法,可以改变!
56
57 **屏蔽显示:**
58
59```shell
60stty -echo #禁止回显
61stty echo #打开回显
62```
63
64测试方法:
65
66```shell
67stty -echo;read;stty echo;read
68```
69
70 **忽略回车符:**
71
72```shell
73stty igncr #开启
74stty -igncr #恢复
75```
76
77 **定时输入:**
78
79```shell
80timeout_read()
81{
82 timeout=$1
83 old_stty_settings=`stty -g`  #save current settings
84 stty -icanon min 0 time 100  #set 10seconds,not 100seconds
85 eval read varname   #=read $varname
86 stty "$old_stty_settings"   #recover settings
87}
88```
89
90更简单的方法就是利用read命令的`-t`选项:
91
92```shell
93read -t 10 varname
94```
95
96