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

Output:

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

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

Output:

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

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.