为什么这样做:
# a.sh
setEnv() {
export TEST_A='Set'
}
如果不是这样:
# b.sh
export TEST_B='Set'
例如:
> source a.sh
> setEnv
> env | grep TEST_A
TEST_A=Set
> b.sh
> env | grep TEST_B
我知道为什么无法运行脚本以及如何使脚本运行(source b.sh
等等),但是我很好奇该函数为何起作用。如果重要的话,这是在OS X上。
执行一个函数本身并不会像启动一个新进程那样b.sh
。
在手册页中(强调最后一句话):
FUNCTIONS
A shell function, defined as described above under SHELL GRAMMAR,
stores a series of commands for later execution. When the name of a
shell function is used as a simple command name, the list of commands
associated with that function name is executed. **Functions are executed
in the context of the current shell; no new process is created to
interpret them (contrast this with the execution of a shell script).**
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句