HP-UX Reference (11i v3 07/02) - 1 User Commands A-M (vol 1)
k
ksh(1) ksh(1)
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
used within a function defines local variables whose scope includes the current function and all functions it
calls.
The special command return is used to return from function calls. Errors within functions return con-
trol 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 when used interac-
tively.
ksh stores the function definitions in the history file. Hence, ksh will not display the function
definitions if the history file is lost or if the
nolog option was on when the function was read. 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 resembling:
[1] 1234
indicating that job number 1 was started asynchronously and had one (top-level) process whose process ID
was 1234.
If you are running a job and want to do something else, type the suspend character (usually ˆZ (Ctrl-Z)) to
send a STOP signal to the current job. The shell then indicates that the job has been ‘Stopped’, and prints
another prompt. The state of this job can be manipulated by using the bg command to put it in the back-
ground, running other commands (while it is stopped or running in the background), and eventually res-
tarting or returning the job to the foreground by using the fg command. A ˆZ takes effect immediately
and resembles an interrupt, since pending output and unread input are discarded when ˆZ is typed.
A job run in the background stops if it tries to read from the terminal. Background jobs normally are
allowed to produce output, but can be disabled by giving the stty tostop command. If the user sets
this tty option, background jobs stop when trying to produce output.
There are several ways to refer to jobs in the shell. A job can be referred to by the process ID of any pro-
cess in the job or by one of the following:
%number The job with the given number.
%string Any job whose command line begins with string.
498 Hewlett-Packard Company − 10 − HP-UX 11i Version 3: February 2007