Files
uTools-Manuals/docs/linux/stty.html
T
fofolee 7ca94f1141 0.0.1
2019-04-08 23:22:26 +08:00

44 lines
1.9 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<h1 id="stty">stty</h1>
<p>修改终端命令行的相关设置</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>stty命令</strong> 修改终端命令行的相关设置。</p>
<h3 id="语法">语法</h3>
<pre><code>stty(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code>-a:以容易阅读的方式打印当前的所有配置;
-g:以stty可读方式打印当前的所有配置。</code></pre>
<h3 id="参数">参数</h3>
<p>终端设置:指定终端命令行的设置选项。</p>
<h3 id="实例">实例</h3>
<p><strong>在命令行下,禁止输出大写的方法:</strong></p>
<pre><code>stty iuclc #开启
stty -iuclc #恢复</code></pre>
<p><strong>在命令行下禁止输出小写:</strong></p>
<pre><code>stty olcuc #开启
stty -olcuc #恢复</code></pre>
<p><strong>打印出终端的行数和列数:</strong></p>
<pre><code>stty size</code></pre>
<p><strong>改变Ctrl+D的方法:</strong></p>
<pre><code>stty eof &quot;string&quot;</code></pre>
<p>系统默认是Ctrl+D来表示文件的结束,而通过这种方法,可以改变!</p>
<p><strong>屏蔽显示:</strong></p>
<pre><code>stty -echo #禁止回显
stty echo #打开回显</code></pre>
<p>测试方法:</p>
<pre><code>stty -echo;read;stty echo;read</code></pre>
<p><strong>忽略回车符:</strong></p>
<pre><code>stty igncr #开启
stty -igncr #恢复</code></pre>
<p><strong>定时输入:</strong></p>
<pre><code>timeout_read()
{
timeout=$1
old_stty_settings=`stty -g`  #save current settings
stty -icanon min 0 time 100  #set 10seconds,not 100seconds
eval read varname   #=read $varname
stty &quot;$old_stty_settings&quot;   #recover settings
}</code></pre>
<p>更简单的方法就是利用read命令的<code>-t</code>选项:</p>
<pre><code>read -t 10 varname</code></pre>
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->