About
A subshell is a process:
- that is started in its own scoped environment
- and therefore does not share any variables (ie context).
How can you create a subshell
With the control operators
( and ) are control operators that executes command in a subshell.
Without the capture
(command1;command2) will execute without capturing the standard stream.
With the capture notation
- $(command) will capture the standard stream.
Example with the capture notation:
foo() {
>&2 echo "std error";
echo "std out";
}
echo $(foo)
std error
std out
With a pipeline
Each part of pipeline will create a subshell.
With the ampersand
With the ampersand, you can create a subshell that runs in the background.