2019-04-21 11:50:48 +08:00

44 lines
2.2 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.

This file contains Unicode characters that might be confused with other characters. 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 class="language-bash">stty(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-a以容易阅读的方式打印当前的所有配置
-g以stty可读方式打印当前的所有配置。</code></pre>
<h3 id="参数">参数</h3>
<p>终端设置:指定终端命令行的设置选项。</p>
<h3 id="实例">实例</h3>
<p><strong>在命令行下,禁止输出大写的方法:</strong></p>
<pre><code class="language-bash">stty iuclc #开启
stty -iuclc #恢复</code></pre>
<p><strong>在命令行下禁止输出小写:</strong></p>
<pre><code class="language-bash">stty olcuc #开启
stty -olcuc #恢复</code></pre>
<p><strong>打印出终端的行数和列数:</strong></p>
<pre><code class="language-bash">stty size</code></pre>
<p><strong>改变Ctrl+D的方法:</strong></p>
<pre><code class="language-bash">stty eof &quot;string&quot;</code></pre>
<p>系统默认是Ctrl+D来表示文件的结束而通过这种方法可以改变</p>
<p><strong>屏蔽显示:</strong></p>
<pre><code class="language-bash">stty -echo #禁止回显
stty echo #打开回显</code></pre>
<p>测试方法:</p>
<pre><code class="language-bash">stty -echo;read;stty echo;read</code></pre>
<p><strong>忽略回车符:</strong></p>
<pre><code class="language-bash">stty igncr #开启
stty -igncr #恢复</code></pre>
<p><strong>定时输入:</strong></p>
<pre><code class="language-bash">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 class="language-bash">read -t 10 varname</code></pre>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->