In the manpage for bash, under the "Compound Commands" section, there are the following two entries:
(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.
( expression ) Returns the value of expression. This may be used to override the normal precedence of operators.
The only difference I can see is that in one, the parentheses have no spaces next to them, and in the other, they do. Is that what actually differentiates grouping vs a subshell, or is it dependent on the context?
In other words, if I run
if ! [ 2 -eq 2 ] || ( [ 2 -eq 2 ] && [ 4 -eq 4 ] ); then echo "hello"; fi
is this just grouping the conditions or running in a subshell?
&&
has higher precedence than||
so the parentheses aren't actually necessary in this case. – Yingling{ list; }
-- a trailing semicolon or newline is required before the close brace. – Primal