HP-UX Reference (11i v2 03/08) - 1 User Commands N-Z (vol 2)
s
sh-posix(1) sh-posix(1)
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.
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 that looks like:
[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 wish to do something else, you can type the suspend character (the
susp
character defined with stty; see stty(1)) to send a
SIGSTOP signal to the current job. The shell then
indicates that the job has been
Stopped
, and prints another prompt. Then you can manipulate the state
of this job by putting it in the background with the bg command, running other commands, and eventu-
ally returning the job to the foreground with the
fg command. A suspend takes effect immediately and
resembles an interrupt, since pending output and unread input are discarded when the suspend is
entered.
A job running in the background stops if it tries to read from the terminal. Background jobs normally are
allowed to produce output, but can be disabled with the
stty tostop command. If the user sets this
terminal 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.
%?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
SIGCHLD
.
If you try to exit from shell while jobs are stopped, you are warned with the message
You have
stopped jobs.
You can use the jobs command to identify them. If you immediately try to exit
again, the shell will not warn you a second time, and the stopped jobs will be terminated.
If you try to leave the shell while jobs are running, you are not warned. The shell exits silently and sets
the parent of the running jobs to the
init process (number 1).
Signals
The
SIGINT and SIGQUIT 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 SIGSEGV (but see also the trap special command).
Execution
Substitutions are made each time a command is executed.
sh checks the command name to determine
whether it matches a special command. If it does, it is executed within the current shell process.
Next,
sh checks the command name to determine whether it matches one of the user-defined functions.
If it does, sh saves the positional parameters, then sets them to the arguments of the function call. The
positional parameter 0 is unchanged. When the function completes or issues a return, sh restores the
positional parameter list. 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 user-defined function or a special command,
sh creates a process and
attempts to execute the command using an exec*() system call (see exec(2)).
Section 1−−818 Hewlett-Packard Company − 20 − HP-UX 11i Version 2: August 2003