Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does a sub shell inherits its parent shell env?

Tags:

bash

shell

sh

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

like image 899
rookie Avatar asked Oct 14 '25 13:10

rookie


1 Answers

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.

like image 72
Samuel Kirschner Avatar answered Oct 17 '25 04:10

Samuel Kirschner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!