Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
sh(1) OSS Shell and Utilities Reference Manual
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.
A job being run in the background will stop if it tries to read from the terminal. Background jobs
are normally allowed to produce output, but this can be disabled by issuing the stty tostop com-
mand. If you set this tty option, then background jobs will stop when they try to produce output
like they do when they try to read input.
There are several ways to refer to jobs in the shell. A job can be referred to by the process ID of
any process of the job, or by one of the following:
%job_number
The job with the given number.
8−28 Hewlett-Packard Company 527188-003