Open System Services Shell and Utilities Reference Manual (G06.28+, H06.05+)
User Commands (k - l) ksh(1)
You can augment the environment for any simple command or function by prefixing it with one
or more parameter assignments. A parameter assignment argument is a word of the form
identifier=value.
Thus, the following two expressions are equivalent (as far as the execution of command is con-
cerned):
TERM=450 command argument ...
(export TERM; TERM=450; command argument ...)
Functions
The function reserved word is used to define shell functions. Shell functions are read in 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 Execution.)
Functions execute in the same process as the caller and share all
files and the present working
directory with the caller. Traps caught by the caller are reset to their default action inside the
function. A trap condition that is not caught or ignored by the function causes the function to ter-
minate and the condition to be 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 special command typeset
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
control to the caller.
Function identifiers can be listed with the -f or +f option of the typeset special command. The
text of functions is also listed with -f. 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 a separate
invocation of the shell. Functions that need to be defined across separate invocations of the shell
should be specified in the ENV file with the -xf option of typeset.
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:
[1] 1234
This line indicates that the job, which was started asynchronously, was job number 1 and had one
(top-level) process, whose process ID was 1234.
If you are running a job and want to do something else, you can enter the Suspend key sequence
(normally <Ctrl-z>), which sends a SIGTSTP signal to the current job. The shell then normally
indicates that the job has been stopped, and it prints another prompt. You can then manipulate
the state of this job, putting it in the background with the bg command, or run some other com-
mands and then eventually bring the job back into the foreground with the foreground command
fg. The job suspension takes effect immediately, and corresponds to the Interrupt key sequence
in that pending output and unread input are discarded. A special key sequence, <Ctrl-y>, does
not generate a SIGTSTP signal until a program attempts to read it. (See the read(2) reference
page for more information.) This key sequence can usefully be typed ahead when you have
prepared some commands for a job that you wish to stop after it has read them.
527188-007 Hewlett-Packard Company 5−21