Interview Prep/Shell Scripting/Arguments, I/O, here-docs, process substitution and subshells

What is the difference between `( ... )` and `{ ...; }`?

BeginnerConceptArguments, I/O, here-docs, process substitution and subshells
Answer

Both group commands so you can redirect or chain them as one unit. ( ) runs in a subshell (isolated state, extra fork). { ...; } runs in the current shell (variables and exit affect the script).

{ echo "== disk =="; df -h; echo "== mem =="; free -m; } > report.txt
[[ -f $cfg ]] || { echo "missing $cfg" >&2; exit 1; }   # exit the script
[[ -f $cfg ]] || ( echo "missing" >&2; exit 1 )         # exits only the subshell!
All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Arguments, I/O, here-docs, process substitution and subshells