- Learning Linux Shell Scripting
- Ganesh Naik
- 117字
- 2021-06-25 22:02:54
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.