HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)
s
sh-posix(1) sh-posix(1)
A compound expression can be constructed from these primitives by using any of the following, listed in
decreasing order of precedence.
(exp) True, if exp is true. Used to group expressions.
!exp True, if exp is false.
exp1
&& exp2 True, if exp1 and exp2 are both true.
exp1
|| exp2 True, if either exp1 or exp2 is true.
Input/Output
Before a command is executed, its input and output can be redirected using a special notation interpreted
by the shell. The following can appear anywhere in a simple-command or may precede or follow a com-
mand and are not passed on to the invoked command. Command and parameter substitution occurs before
word or digit is used, except as noted below. File name generation occurs only if the pattern matches a sin-
gle 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.
>|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 param-
eter substitution, command substitution or file name generation is performed on
word. The resulting document, called a here-document, becomes the standard input.
If any character of word is quoted, no interpretation is placed upon the characters of
the document. Otherwise, parameter and command substitution occurs,
\newline 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
document.
<&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 descriptor
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 numbered
file descriptor, allowing other commands to write to them and read from them. If the input of the current
HP-UX 11i Version 1: September 2005 − 18 − Hewlett-Packard Company Section 1−−909