UNIX export命令 [英] UNIX export command
问题描述
我想了解使用导出
命令。
我试着用男人的出口
,但该命令没有手册。
I tried using man export
, but there is no manual for this command.
任何人都可以请帮我了解使用
出口UNIX的?
Can anyone please help me out understanding the use of export
in UNIX?
推荐答案
当你执行一个程序的子程序继承父的环境变量。例如,如果 $ HOME
在父设置为 /根
那么孩子的 $ HOME
变量也被设置为 /根
。
When you execute a program the child program inherits its environment variables from the parent. For instance if $HOME
is set to /root
in the parent then the child's $HOME
variable is also set to /root
.
这仅适用于被标记为出口环境变量。如果您设置在命令行的变量像
This only applies to environment variable that are marked for export. If you set a variable at the command-line like
$ FOO="bar"
该变量不会在子进程可见。除非你将其导出:
That variable will not be visible in child processes. Not unless you export it:
$ export FOO
您可以(在老学校SH但不是)这两个语句合并成一个单一在bash:
You can combine these two statements into a single one in bash (but not in old-school sh):
$ export FOO="bar"
下面是呈现出口和非出口变量之间的区别一个简单的例子。要了解发生了什么知道 SH -c
创建一个子shell进程它继承父shell的环境。
Here's a quick example showing the difference between exported and non-exported variables. To understand what's happening know that sh -c
creates a child shell process which inherits the parent shell's environment.
$ FOO=bar
$ sh -c 'echo $FOO'
$ export FOO
$ sh -c 'echo $FOO'
bar
注意::要得到帮助的外壳内置命令使用帮助出口
。 shell内置的是你的shell的一部分,而不是独立的可执行文件一样的命令 /斌/ LS
。
Note: To get help on shell built-in commands use help export
. Shell built-ins are commands that are part of your shell rather than independent executables like /bin/ls
.
这篇关于UNIX export命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!