When does a sub shell inherits its parent shell en

2019-09-14 20:42发布

问题:

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.



标签: bash shell sh