1:use {} to group commands together. eg.
$ pwd; ls; cd ../elsewhere; pwd; ls > /tmp/all.out
The final redirect applies only to the last command, the last ls on the line.
$ {pwd; ls; cd ../elsewhere; pwd; ls} > /tmp/all.out
the redirection applies to the output from all commands in the group.
2: use () to create subshell. the commands enclosed in the parentheses run in another instance of the shell, a child of the current shell called subshell.
The subshell is almost identical to the current shell's environment( ie., variables, including $PATH), but traps are handled differently.
$ pwd; ls; cd ../elsewhere; pwd; ls > /tmp/all.out
The final redirect applies only to the last command, the last ls on the line.
$ {pwd; ls; cd ../elsewhere; pwd; ls} > /tmp/all.out
the redirection applies to the output from all commands in the group.
2: use () to create subshell. the commands enclosed in the parentheses run in another instance of the shell, a child of the current shell called subshell.
The subshell is almost identical to the current shell's environment( ie., variables, including $PATH), but traps are handled differently.