GNU Info

Info Node: (bashref.info)Command Grouping

(bashref.info)Command Grouping


Prev: Conditional Constructs Up: Shell Commands
Enter node , (file) or (file)node

Grouping Commands
-----------------

   Bash provides two ways to group a list of commands to be executed as
a unit.  When commands are grouped, redirections may be applied to the
entire command list.  For example, the output of all the commands in
the list may be redirected to a single stream.

`()'
          ( LIST )

     Placing a list of commands between parentheses causes a subshell
     to be created, and each of the commands in LIST to be executed in
     that subshell.  Since the LIST is executed in a subshell, variable
     assignments do not remain in effect after the subshell completes.

`{}'
          { LIST; }

     Placing a list of commands between curly braces causes the list to
     be executed in the current shell context.  No subshell is created.
     The semicolon (or newline) following LIST is required.

   In addition to the creation of a subshell, there is a subtle
difference between these two constructs due to historical reasons.  The
braces are `reserved words', so they must be separated from the LIST by
`blank's.  The parentheses are `operators', and are recognized as
separate tokens by the shell even if they are not separated from the
LIST by whitespace.

   The exit status of both of these constructs is the exit status of
LIST.


automatically generated by info2www version 1.2.2.9