HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)

s
sh-bourne(1) sh-bourne(1)
....
Prompting
When used interactively, the shell prompts with the value of
PS1 before reading a command. If at any
time a new-line is typed and further input is needed to complete a command, the secondary prompt (i.e.,
the value of
PS2) is issued.
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 can precede or follow a command
and are not passed on to the invoked command; substitution occurs before word or digit is used:
<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 then it is
created; otherwise, it is truncated to zero length.
>>word Use file word as standard output. If the file exists then output is appended to it (by
first seeking to the end-of-file); otherwise, the file is created.
<<[-]word The shell input is read up to a line that is the same as word, or to an end-of-file. The
resulting 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, (unescaped)
\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 document.
<&digit Use the file associated with file descriptor digit as standard input. Similarly for the
standard output using >&digit (see dup(2)). Note that digit must be in the range 0
through 9.
<&- The standard input is closed. Similarly for the standard output using >&-.
If any of the above is preceded by a digit in the range 0 through 9, the file descriptor that becomes associ-
ated with the file is that specified by the digit (rather than the default 0 or 1). For example:
... 2>&1
associates file descriptor 2 with the file currently associated with le descriptor 1. Note that this type of
I/O redirection is necessary when synchronously collecting standard output and standard error output in
the same file. Redirecting standard output and standard error separately causes asynchronous collection of
data at the destination (information written to standard output can be subsequently over-written by infor-
mation written to standard error and vice-versa).
The order in which redirections are specified is significant. The shell evaluates redirections left-to-right.
For example:
... 1>xxx 2>&1
first associates file descriptor 1 with file xxx. It associates file descriptor 2 with the file associated with file
descriptor 1 (i.e. xxx). If the order of redirections is reversed, file descriptor 2 is associated with the termi-
nal (assuming file descriptor 1 was originally) and file descriptor 1 is associated with file xxx.
If a command is followed by &, the default standard input for the command is the empty file /dev/null .
Otherwise, the environment for executing a command contains the file descriptors of the invoking shell as
modified by input/output specifications.
Redirection of output is not allowed in the restricted shell.
Environment
The environment (see environ(5)) is a list of name-value pairs that is passed to an executed program in
the same way as a normal argument list. The shell interacts with the environment in several ways. On
invocation, the shell scans the environment and creates a parameter for each name found, giving it the
corresponding value. Executed commands inherit the same environment. If the user modifies the value of
any of these parameters or creates new parameters, none of these affects the environment unless the
export command is used to bind the shell’s parameter to the environment (see also set -a). To remove
a parameter from the environment, use the unset command. The environment seen by any executed
command is thus composed of any unmodified name-value pairs originally inherited by the shell, minus any
pairs removed by unset, plus any modifications or additions, all of which must be noted in export
HP-UX 11i Version 1: September 2005 4 Hewlett-Packard Company Section 1885