ksh.1 (2010 09)

k
ksh(1) ksh(1)
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 exam-
ple,
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.
Functions are executed like commands, with the arguments passed as positional parameters (see Execu-
tion 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, variables 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.
Functions 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 background, running other commands (while it is stopped or running in the background), and eventu-
ally restarting 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
10 Hewlett-Packard Company 10 HP-UX 11i Version 3: September 2010