[prev] [index] [next]

Grouping

Commands can be grouped using ( ... ) or { ... }

(cmd1 ; ... cmdn) are executed in a new sub-shell.

{cmd1 ; ... cmdn } are executed in the current shell.

Exit status of group is exit status of last command.

Beware: state of sub-shell (e.g. $PWD, other variables) is lost after (...), hence

$ cd /usr/share;  x=123
$ ( cd $HOME;  x=abc; )
$ echo $PWD $x
/usr/share 123
$ { cd $HOME;  x=abc; }
$ echo $PWD $x
/home/cs2041 abc