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

43 lines
2.2 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

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="echo">echo</h1>
<p>输出指定的字符串或者变量</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>echo命令</strong> 用于在shell中打印shell变量的值或者直接输出指定的字符串。linux的echo命令在shell编程中极为常用, 在终端下打印变量value的时候也是常常用到的因此有必要了解下echo的用法echo命令的功能是在显示器上显示一段文字一般起到一个提示的作用。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">echo(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">-e激活转义字符。</code></pre>
<p>使用<code>-e</code>选项时,若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:</p>
<ul>
<li>发出警告声;</li>
<li></li>
<li></li>
<li></li>
<li>换行且光标移至行首;</li>
<li></li>
<li></li>
<li></li>
<li>\ 插入;</li>
<li>插入nnn八进制所代表的ASCII字符</li>
</ul>
<h3 id="参数">参数</h3>
<p>变量:指定要打印的变量。</p>
<h3 id="实例">实例</h3>
<p>用echo命令打印带有色彩的文字</p>
<p><strong>文字色:</strong></p>
<pre><code class="language-bash">echo -e &quot;\e[1;31mThis is red text\e[0m&quot;
This is red text</code></pre>
<ul>
<li><code>\e[1;31m</code> 将颜色设置为红色</li>
<li><code>\e[0m</code> 将颜色重新置回</li>
</ul>
<p>颜色码:重置=0黑色=30红色=31绿色=32黄色=33蓝色=34洋红=35青色=36白色=37</p>
<p><strong>背景色</strong> </p>
<pre><code class="language-bash">echo -e &quot;\e[1;42mGreed Background\e[0m&quot;
Greed Background</code></pre>
<p>颜色码:重置=0黑色=40红色=41绿色=42黄色=43蓝色=44洋红=45青色=46白色=47</p>
<p><strong>文字闪动:</strong></p>
<pre><code class="language-bash">echo -e &quot;\033[37;31;5mMySQL Server Stop...\033[39;49;0m&quot;
</code></pre>
<p>红色数字处还有其他数字参数0 关闭所有属性、1 设置高亮度加粗、4 下划线、5 闪烁、7 反显、8 消隐</p>
<!-- Linux命令行搜索引擎https://jaywcjlove.github.io/linux-command/ -->