HP-UX Reference (11i v1 05/09) - 1 User Commands N-Z (vol 2)

s
sh-posix(1) sh-posix(1)
[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 char-
acter defined with
stty; see stty(1)) to send a
SIGSTOP signal to the current job. The shell then indi-
cates 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 eventually
returning the job to the foreground with the
fg command. A suspend takes effect immediately and resem-
bles 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 posi-
tional parameter 0 is unchanged. When the function completes or issues a return, sh restores the posi-
tional parameter list. The value of a function is the value of the last command executed. A function is exe-
cuted 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)).
The shell parameter PATH defines the search path for the directory containing the command. Alternative
directory names are separated by a colon (:). The default path is /usr/bin: (specifying /usr/bin,
and the current directory, in that order). Note that the current directory is specified by a null path name,
which can appear immediately after the equal sign, between colon delimiters, or at the end of the path list.
The search path is not used if the command name contains a /. Otherwise, each directory in the path is
searched for an executable file. If the file has execute permissions but is not a directory or an executable
object code file, it is assumed to be a script file, which is a file of data for an interpreter. If the first two
characters of the script file are #!, exec*() expects an interpreter path name to follow. exec*() then
attempts to execute the specified interpreter as a separate process to read the entire script file. If a call to
exec*() fails, sh is spawned to interpret the script file. All nonexported aliases, functions, and named
parameters are removed in this case. If the shell command file does not have read permission, or if the
setuid and/or setgid bits are set on the file, the shell executes an agent to set up the permissions and
HP-UX 11i Version 1: September 2005 20 Hewlett-Packard Company Section 1911