When does a sub shell inherits its parent shell en

2019-09-14 19:48发布

Under what circumstances is the environment of the shell passed to the sub-shell?

标签: bash shell sh
1条回答
仙女界的扛把子
2楼-- · 2019-09-14 20:31

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.

查看更多
登录 后发表回答