Files
uTools-Manuals/docs/linux/declare.html
T

23 lines
1.6 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="declare">declare</h1>
<p>声明或显示shell变量</p>
<h2 id="补充说明">补充说明</h2>
<p><strong>declare命令</strong> 用于声明和显示已存在的shell变量。当不提供变量名参数时显示所有shell变量。declare命令若不带任何参数选项,则会显示所有shell变量及其值。declare的功能与typeset命令的功能是相同的。</p>
<h3 id="语法">语法</h3>
<pre><code class="language-bash">declare(选项)(参数)</code></pre>
<h3 id="选项">选项</h3>
<pre><code class="language-bash">+/-&quot;-&quot;可用来指定变量的属性,&quot;+&quot;则是取消变量所设的属性;
-f:仅显示函数;
r:将变量设置为只读;
x:指定的变量会成为环境变量,可供shell以外的程序来使用;
i:[设置值]可以是数值,字符串或运算式。</code></pre>
<h3 id="参数">参数</h3>
<p>shell变量:声明shell变量,格式为“变量名=值”。</p>
<h3 id="实例">实例</h3>
<p>首先使用declare命令定义shell变量“test”,并且将其值设置为“wangchujiang.com”,输入如下命令:</p>
<pre><code class="language-bash">declare test=&#39;wangchujiang.com&#39; #定义并初始化shell变量</code></pre>
<p>上面的命令执行后,再使用echo命令将该shell变量值输出,输入如下命令:</p>
<pre><code class="language-bash">echo $test #输出shell变量的值</code></pre>
<p>上面的指令执行后,其输出的结果如下:</p>
<pre><code class="language-bash">wangchujiang.com</code></pre>
<!-- Linux命令行搜索引擎:https://jaywcjlove.github.io/linux-command/ -->