定义带或不带导出的变量 [英] Defining a variable with or without export
问题描述
export
有什么用?
有什么区别:
export name=value
和
name=value
推荐答案
export
使变量可用于子进程.
export
makes the variable available to sub-processes.
也就是说,
export name=value
表示变量名称可用于从该 shell 进程运行的任何进程.如果您希望进程使用此变量,请使用 export
,然后从该 shell 运行该进程.
means that the variable name is available to any process you run from that shell process. If you want a process to make use of this variable, use export
, and run the process from that shell.
name=value
表示变量范围仅限于 shell,不能用于任何其他进程.您可以将其用于(例如)循环变量、临时变量等.
means the variable scope is restricted to the shell, and is not available to any other process. You would use this for (say) loop variables, temporary variables etc.
请务必注意,导出变量不会使其对父进程可用.也就是说,在派生的进程中指定和导出变量不会使其在启动它的进程中可用.
It's important to note that exporting a variable doesn't make it available to parent processes. That is, specifying and exporting a variable in a spawned process doesn't make it available in the process that launched it.
这篇关于定义带或不带导出的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!