Under what circumstances is the environment of the shell passed to the sub-shell?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With