本文介绍了&是什么QUOT;出口"在shell编程吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,变量赋值是一样的无论是或不是由出口pceded $ P $。对于它是什么?

As far as I can tell, variable assignment is the same whether it is or is not preceded by "export". What's it for?

推荐答案

导出的变量(如 $ HOME $ PATH )是可用于其他项目。
常规(非导出)变量不可用于其他程序。

Exported variables (such as $HOME and $PATH) are available to other programs.Regular (non-exported) variables are not available to other programs.

$ env | grep '^variable='
$                                 # No environment variable called variable
$ variable=Hello                  # Create local (non-exported) variable with value
$ env | grep '^variable='
$                                 # Still no environment variable called variable
$ export variable                 # Mark variable for export to child processes
$ env | grep '^variable='
variable=Hello
$
$ export other_variable=Goodbye   # create and initialize exported variable
$ env | grep '^other_variable='
other_variable=Goodbye
$

有关详细信息,请参阅。

For more information, see the entry for the export builtin in the GNU Bash manual.

请注意,非出口的变量将可以通过运行子shell(...)和类似的符号:

Note that non-exported variables will be available to subshells run via ( ... ) and similar notations:

$ othervar=present
$ (echo $othervar; echo $variable; variable=elephant; echo $variable)
present
Goodbye
elephant
$ echo $variable
Goodbye
$

子shell可以在不影响父shell变量,当然。

The subshell cannot affect the variable in the parent shell, of course.

关于子shell的一些信息可以在并在Bash的手册。

Some information about subshells can be found under command grouping and command execution environment in the Bash manual.

这篇关于&是什么QUOT;出口"在shell编程吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 00:10