HP-UX Reference (11i v1 00/12) - 1 User Commands A-M (vol 1)

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man1/!!!intro.1
________________________________________________________________
___ ___
k
ksh(1) ksh(1)
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. 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 process
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.
%?string Any job whose command line contains string.
%% Current job.
%+ Equivalent to %%.
%- Previous job.
The shell learns immediately when a process changes state. It informs the user when a job is blocked and
prevented from further progress, but only just before it prints a prompt.
When the monitor mode is on, each background job that completes triggers any trap set for CHLD.
Attempting to leave the shell while jobs are running or stopped produces the warning, You have
stopped (running) jobs
. Use the jobs command to identify them. An immediate attempt to
exit again terminates the stopped jobs; the shell does not produce a warning the second time.
Signals
The INT and QUIT signals for an invoked command are ignored if the command is followed by
& and the
monitor option is off. Otherwise, signals have the values inherited by the shell from its parent, with the
exception of signal 11 (but see also the trap command below).
Execution
Substitutions are made each time a command is executed. If the command name matches one of the Spe-
cial Commands listed below, it is executed within the current shell process. Next,
ksh checks the com-
mand name to determine whether it matches one of the user-defined functions. If it does, ksh saves the
positional parameters and then sets them to the arguments of the function call. The positional parameter
0 is set to the function name. When the function completes or issues a return, ksh restores the posi-
tional parameter list and executes any trap set on EXIT within the function. The value of a function is the
value of the last command executed. A function is executed in the current shell process. If a command
name is not a special command or a user-defined function,
ksh creates a process and attempts to
HP-UX Release 11i: December 2000 − 10 − Section 1−−405
___
___