
632
|
Chapter 6: The Bash Shell and Korn Shell
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
No space should appear between file descriptors and a redirection symbol;
spacing is optional in the other cases.
Bash allows multi-digit file descriptor numbers. The other shells do not.
Examples
$ cat part1 > book
$ cat part2 part3 >> book
$ mail tim < report
$ sed 's/^/XX /g' << END_ARCHIVE
> This is often how a shell archive is "wrapped",
> bundling text for distribution. You would normally
> run sed from a shell program, not from the command line.
> END_ARCHIVE
XX This is often how a shell archive is "wrapped",
XX bundling text for distribution. You would normally
XX run sed from a shell program, not from the command line.
To redirect standard output to standard error:
$ echo "Usage error: see administrator" 1>&2
The following command sends output (files found) to filelist and error messages
(inaccessible files) to file no_access:
$ find / -print > filelist 2>no_access
Coprocesses
Coprocesses are a feature of the Korn shell only.
Moving the coprocess input and output file descriptors to standard file descrip-
tors allows you to open multiple coprocesses.
cmd >& file Same. Bash only.
cmd > f1 2>f2 Send standard output to file f1, standard error to file f2.
cmd | tee files Send output of cmd to standard output (usually the terminal) and to files