Text-only Table of Contents (frame/ no frame)
(14) I/O redirection and pipelines Previous Top Next

I/O redirection and pipelines

Any simple command (or shell function, or compound command) may have its input and output redirected using the following operators. This is performed by the shell before the command is run.

Output redirection

> filename
Standard ouput (file descriptor 1) is redirected to the named file. The file is overwritten unless the noclobber option is set. The file is created if it does not exist. Less detail
The special device file /dev/null can be used to explicitly discard unwanted output. Reading from /dev/null results in an End of File status.
>> filename
Standard ouput is appended to the named file. The file is created if it does not exist.
>| filename
Output redirect, and override the noclobber option, if set.

Input redirection

< filename
Standard input (file descriptor 0) is redirected to the named file. The file must already exist.

Command pipelines

command | command [ | command ...]
Pipe multiple commands together. The standard output of the first command becomes the standard input of the second command. All commands run simultaneously, and data transfer happens via memory buffers. This is one of the most powerful constructs in Unix. Compound commands may also be used with pipes. Pipes play very nicely with multiprocessor systems. Less detail
No more than one command in a pipeline should be interactive (attempt to read from the terminal). This construct is much more efficient than using temporary files, and most standard Unix utilities are designed such that they work well in pipelines.

The exit status of a pipeline is the exit status of the last command. In compound commands, a pipeline can be used anywhere a simple command could be used.

Previous Top Next

ioredirection.src  last modified Mar 26, 2010 Introduction Table of Contents
(frame/no frame)
(single file)
© Dartmouth College