MPE/iX Shell and Utilities Reference Manual, Vol 2
sh(1) MPE/iX Shell and Utilities sh(1)
File Descriptors and Redirection
The shell sometimes refers to files using file descriptors. A file descriptor is a number in the
range 0 through 9. It may have any number of digits. For example, the file descriptors 001
and 01 are identical to file descriptor 1. Various operations (for example, exec) can associ-
ate a file descriptor with a particular file.
Some file descriptors are set up at the time the shell starts up. These are the standard
input/output streams:
• standard input (file descriptor 0)
• standard output (file descriptor 1)
• standard error (file descriptor 2)
Commands running under the shell can use these descriptors and streams too. When a com-
mand runs under the shell, the streams are normally associated with your terminal; however,
you can redirect these file descriptors to associate them with other files (so that I/O on the
stream takes place on the associated file instead of your terminal). In fact, the shell lets you
redirect the I/O streams associated with file descriptors 0 through 9, using the following com-
mand line constructs.
number<file
uses file for input on the file descriptor number. If you omit number,asin <file, the
default is 0; this redirects the standard input.
number>file
uses file for output on the file descriptor number. If you omit number,asin >file, the
default is 1; this redirects the standard output. The shell creates the file if it doesn’t
already exist. The redirection fails if the file already exists and noclobber is set
(see set(1)).
number>|file
is similar to number>file but if file already exists, overwrites the current contents of
the file.
number<>file
uses file for input and output with the file descriptor number. This is most useful
when the file is another terminal or modem line. If you omit number,asin <>file,
the default number is zero; this redirects the standard input. Output written to the file
overwrites the current contents of the file (if any). The shell creates the file if it
doesn’t already exist.
number>>file
is similar to number > file except that output is appended to the current contents of
file (if any).
1-536 Commands and Utilities