擅长:python、mysql、java
<p>啊哈!解决办法很简单!</p>
<p>我用简单的<code>$ A=5</code>命令设置变量;当您使用<code>$ export B="kkk"</code>时,一切都很好。</p>
<p>即<a href="https://stackoverflow.com/questions/1158091/bash-defining-a-variable-with-or-without-export">beca</a><a href="https://www.gnu.org/software/bash/manual/html_node/Environment.html#Environment" rel="noreferrer">use</a><code>export</code>使变量可用于子进程:</p>
<ul>
<li>它在shell中创建一个变量</li>
<li>并将其导出到外壳的<code>environment</code>中</li>
<li>列表<code>environment</code>传递给shell的子进程。</li>
</ul>
<p>普通的<code>$ A="kkk"</code>只在shell中创建变量,而不使用<code>environment</code>。</p>
<p>从shell调用的解释器从父shell获得<code>environment</code>。所以实际上,变量应该在之前导出到<code>environment</code>。</p>