Process Management
Subshell Isolation
Changes Stay Inside
Parentheses run commands in a subshell. Variable changes inside the subshell do not overwrite the parent shell's variables.
Program
Play the script to compare the value inside a subshell with the value after it exits.
subshell_isolation.sh
#!/usr/bin/env bash
start=
value=$start
(
value=$((value + 10))
echo "inside=$value"
)
echo "outside=$value"
#!/usr/bin/env bash
start=
value=$start
(
value=$((value + 10))
echo "inside=$value"
)
echo "outside=$value"
#!/usr/bin/env bash
start=
value=$start
(
value=$((value + 10))
echo "inside=$value"
)
echo "outside=$value"
subshell
`( ... )` runs commands in a child shell process.
isolation
Assignments inside the subshell do not change the parent shell.
parent value
After the subshell finishes, the parent `value` is still the original value.