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

s
sh-posix(1) sh-posix(1)
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.
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. Exe-
cuted commands inherit the environment. If the user modifies the values of these parameters or creates
new ones by using the
export or typeset -x
special 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 may 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,
both the following
TERM=450 cmd args
(export TERM; TERM=450; cmd args)
are equivalent (as far as the execution of cmd is concerned, except for the special commands that are pre-
ceded 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 a=b c
set -k
echo a=b c
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 command (described in the "Compound Commands" subsection) defines 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 the "Execu-
tion" subsection.)
Functions execute in the same process as the caller and share all files and current working directory with
the caller. Traps defined by the caller remain in effect within the function until another
trap command is
executed. Traps set within a function remain in effect after the function returns. Ordinarily, variables are
shared between the calling program and the function. However, the
typeset special command can be
used within a function to define local variables whose scope includes the current function and all functions
it calls.
The return special command is used to return from function calls. Errors within functions return control
to the caller.
Function identifiers can be listed with the +f option of the typeset special command. Function
identifiers and the associated text of the functions can be listed with the -f option. Functions can be
undefined with the -f option of the unset special command.
Ordinarily, functions are unset when the shell executes a shell script. The -xf option of the typeset
command allows a function to be exported to scripts that are executed without reinvoking the shell. Func-
tions that must be defined across separate invocations of the shell should be placed in the ENV file.
Jobs
If the monitor option of the set command is turned on, an interactive shell associates a job with each
pipeline. It keeps a table of current jobs, printed by the jobs command, and assigns them small integer
numbers. When a job is started asynchronously with &, the shell prints a line that looks like:
Section 1910 Hewlett-Packard Company 19 HP-UX 11i Version 1: September 2005