Command grouping

Commands may also be grouped so that all of the output is either piped to another command or redirected to a file:

    $ ( ls; pwd; date ) > outputfile

The output of each of the commands is sent to the file, outputfile. The spaces inside the parentheses are necessary:

    $ ( w ; date ) > whoandwhen

The output of the w command and date will be redirected to the whoandwhen file:

    $ (echo "***x.c***";cat x.c) > log.txt


This redirects the content of x.c with a heading ***x.c*** to the file out:

    $ (pwd; ls; date) > log.txt


This redirects the output of commands pwd, ls, and date in the log.txt file.

Get Learning Linux Shell Scripting - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.