() executes the statements in a new subshell, with separate state. {} executes stuff in the current shell.
Example:
Code:
(aVariable="hello"); echo $aVariable
this doesn't print "hello" because the variable was assigned inside a new shell, whose state was discarded when the () expression ended. Think of variable scoping in C; variables live and die inside the block where they're declared.
Code:
{aVariable="hello"; }; echo $aVariable
this prints "hello" because the variable was assigned in the same shell as the next statement.
It's the same difference as:
and
Also, yes, you need a semicolon to end the last statement inside {}; that's how the shell's grammar is defined.
Kind of how you can either do this:
Code:
if $condition; then $statements; fi
or this, using newlines instead of semicolons to separate the syntax parts:
Code:
if $condition
then
$statements
fi
According to the bash man page, it's different from () because { and } are reserved words instead of metacharacters, which means they don't automatically cause word breaks. Presumably the same applies in the rest of the shells.