Under what circumstances is the environment of the shell passed to the sub-shell?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
A subshell always gets all variables from the parent shell.
man bash
will describe all the circumstances in which a subshell is used, which are mainly:
command &
command | command
and
( command )
The so called environment only includes environment variables (export variable
), and is passed on to every sub-process. Even when invoking bash -c command
, which is not a sub-shell but a completely new bash instance.
In both cases changed values are not passed back to the parent process.