Command Reference Guide

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man1/!!!intro.1
________________________________________________________________
___ ___
k
ksh(1) ksh(1)
Redirection order is significant because the shell evaluates redirections referencing file descriptors in terms
of the currently open file associated with the specified file descriptor at the time of evaluation. For exam-
ple:
... 1>fname 2>&1
first assigns file descriptor 1 (standard output) to file fname , then assigns file descriptor 2 (standard error)
to the file assigned to file descriptor 1; i.e., fname. On the other hand, if the order of redirection is reversed
as follows:
... 2>&1 1>fname
file descriptor 2 is assigned to the current standard output (user terminal unless a different assignment is
inherited). File descriptor 1 is then reassigned to file fname without changing the assignment of file
descriptor 2.
The input and output of a co-process can be moved to a numbered file descriptor allowing other commands
to write to them and read from them using the above redirection operators. If the input of the current co-
process is moved to a numbered file descriptor, another co-process can 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.
Environment
The environment (see environ(5)) is a list of name-value pairs passed to an executed program much like a
normal argument list. The names must be identifiers and the values are character strings. The shell
interacts with the environment in several ways. When invoked, the shell scans the environment and
creates a parameter for each name found, gives it the corresponding value, and marks it export.Executed
commands inherit the environment. If the user modifies the values of these parameters or creates new
ones by using the
export or typeset -x commands, the values become part of the environment. The
environment seen by any executed command is thus composed of any name-value pairs originally inherited
by the shell whose values can be modified by the current shell, plus any additions which must be noted in
export or typeset -x commands.
The environment for any simple-command or function can be augmented by prefixing it with one or more
parameter assignments. A parameter assignment argument takes the form identifier
=value. For example,
TERM=450 cmd args
and
(export TERM; TERM=450;
cmd args)
are equivalent (as far as the above execution of cmd is concerned except for special commands listed below
that are preceded by a percent sign).
If the -k option is set, all parameter assignment arguments are placed in the environment, even if they
occur after the command name. The following echo statement prints a=b c. After the -k option is set,
the second echo statement prints only c:
echo a=b c
set -k
echo a=b c
This feature is intended for use with scripts written for early versions of the shell, and its use in new
scripts is strongly discouraged. It is likely to disappear someday.
Functions
The function keyword (described in the Commands section above) is used to define shell functions.
Shell functions are read and stored internally. Alias names are resolved when the function is read. Func-
tions are executed like commands, with the arguments passed as positional parameters (see Execution
below).
Functions execute in the same process as the caller except that command substitution of a function creates
a new process. Functions share all files and present working directory with the caller. Traps caught by the
caller are reset to their default action inside the function. If a function does not catch or specifically ignore
a trap condition, the function terminates and the condition is passed on to the caller. A trap on
EXIT set
inside a function is executed after the function completes in the environment of the caller. Ordinarily, vari-
ables are shared between the calling program and the function. However, the
typeset special command
Section 1404 9 HP-UX Release 11i: December 2000
___
___