Grouping commands

{ <LIST>; }
or
{
<LIST>
}

The list <LIST> is simply executed in the current shell environment. The list must be terminated with a newline or semicolon. For parsing reasons, the curly braces must be separated from <LIST> by a semicolon and blanks if they're in the same line!

This is known as a group command. The return status is the exit status (exit code) of the list.

The input and output filedescriptors are cumulative:

{
  echo "PASSWD follows"
  cat /etc/passwd
  echo
  echo "GROUPS follows"
  cat /etc/group
} >output.txt

This compound command also usually is the body of a function definition, though not the only compound command that's valid there:

print_help() {
  echo "Options:"
  echo "-h           This help text"
  echo "-f FILE      Use config file FILE"
  echo "-u USER      Run as user USER"
}

See also

syntax/ccmd/grouping_plain.txt · Last modified: 2009/02/24 07:26 (external edit)
www.chimeric.de Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0