How are parentheses interpreted at the command line?
Parentheses denote a subshell in bash. To quote the man bash
page:
(list) list is executed in a subshell environment (see COMMAND
EXECUTION ENVIRONMENT below). Variable assignments and builtin
commands that affect the shell's environment do not remain in
effect after the command completes. The return status is the
exit status of list.
where a list
is just a normal sequence of commands.
This is actually quite portable and not specific to just bash
though. The POSIX Shell Command Language spec has the following description for the (compound-list)
syntax:
Execute compound-list in a subshell environment; see Shell Execution Environment. Variable assignments and built-in commands that affect the environment shall not remain in effect after the list finishes.
A command list embedded between parentheses runs as a subshell.
Variables in a subshell are not visible outside the block of code in the subshell. They are not accessible to the parent process, to the shell that launched the subshell. These are, in effect, local variables.
See Linuxtopia - Chapter 20. Subshells