sh-posix.1 (2010 09)
s
sh-posix(1) sh-posix(1)
before word or digit is used, except as noted below. File name generation occurs only if the pattern
matches a single file and blank interpretation is not performed.
<word Use file word as standard input (file descriptor
0).
>word Use file word as standard output (file descriptor
1). If the file does not exist, it is
created. If the file exists, and the
noclobber option is on, an error occurs; other-
wise, the file is truncated to zero length. Note that the
noclobber test is only
applied to regular files, not to named pipes or other file types.
>|word Same as >, except that it overrides the
noclobber option.
>>word Use file word as standard output. If the file exists, output is appended to it (by first
searching for the end-of-file); otherwise, the file is created.
<>word Open file word for reading and writing as standard input.
<<[-]word The shell input is read up to a line that matches word, or to an end-of-file. No
parameter substitution, command substitution or file name generation is performed
on word. The resulting document, called a here-document, becomes the standard
input. See also the WARNINGS section.
If any character of word is quoted, no interpretation is placed upon the characters
of the document. Otherwise, parameter and command substitution occurs,
\new-
line is ignored, and \ must be used to quote the characters \, $,
‘, and the first
character of word .
If
- is appended to <<, all leading tabs are stripped from word and from the docu-
ment.
<&digit The standard input is duplicated from file descriptor digit (see dup (2)).
>&digit The standard output is duplicated to file descriptor digit (see dup(2)).
<&- The standard input is closed.
>&- The standard output is closed.
<&p The input from the coprocess is moved to standard input.
>&p The output to the coprocess is moved to standard output.
If any of the above redirections is preceded by a digit (
0 to 9), the file descriptor used is the one specified
by the digit, instead of the default 0 (standard input) or 1 (standard output). For example:
2>&1
means open file descriptor 2 for writing as a duplicate of file descriptor 1. Output directed to file descrip-
tor 2 is written in the same location as output to file descriptor 1.
Order is significant in redirection. The shell evaluates each redirection in terms of the (file descriptor ,
file) assignment at the time of evaluation. For example:
1>fname 2>&1
first assigns file descriptor 1 to file fname. It then assigns file descriptor 2 to the file assigned to file
descriptor 1 (that is, fname).
If the order of redirection is reversed, as in
2>&1 1>fname
file descriptor 2 is assigned to the file assigned to file descriptor 1 (probably the terminal) and then file
descriptor 1 is assigned to file fname.
By using the redirection operators above, the input and output of a coprocess may be moved to a num-
bered file descriptor, allowing other commands to write to them and read from them. If the input of the
current coprocess is moved to a numbered file descriptor, another coprocess may be started.
If a command is followed by & and job control is inactive, the default standard input for the command is
the empty file /dev/null. Otherwise, the environment for the execution of a command contains the file
descriptors of the invoking shell as modified by input/output specifications.
18 Hewlett-Packard Company − 18 − HP-UX 11i Version 3: September 2010