The previous section demonstrated the power of passing the output of a
command to somewhere other than to the screen - to another command.
This is a very useful feature, and the C shell provides two ways other
than command substitution to accomplish it.
The first of these is redirections.
Redirection allows the output of a command, or more generally, group
of commands, to a file or device.
There are four basic types of redirection operations.
command > filename redirection sends the output from the
command to a file called
If this file does not exist it is created and the output is put there.
If the file does exist, any contents that might be contained in it are
erased and then the output is placed into the empty file.
command < filename redirection takes the contents of
filename and uses them as input to
command >> filename works precisely the same as
with the exception that if the file it is to write to exists, it
appends the output to the end of the file rather than eraseing the
<< takes input from the keyboard as input.
These four basic redirections make up the basis for
table 4.1 which contains all of the redirections possible
in the C shell:
Table 4.1: Redirections possible in the C shell.
Notice that all of the redirections with the
! symbol refer
noclobber having been set.
noclobber is a predefined shell variable (refer to the section on
variables) that prevents existing files from being overwritten by
! symbol overrides this variable if it is set.
It is also important to realize that when the
<< redirection is
used, the shell will make
filename, and variable
substitutions unless the input string is surrounded by quotes of some
For each of these substitutions, a device, such as the null device, or
a file descriptor could be put in place of file.
Another way to pass output of a command to another command is by using
a pipe (
The pipe is similar to the left single quoted command substitution
described above, with the exception that it is formatted differently:
command1 | command2
command1 and passes the result to
For example, the following are equivalent:
% wc `ls`
is the same as
% ls | wc
Pipelines, redirections, and command substitions can be mixed in any way that the user desires.