2 .\" Copyright (c) 2007 Sun Microsystems, Inc. - All Rights Reserved.
4 .\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH TRAP 1 "Nov 20, 2007"
10 trap, onintr \- shell built-in functions to respond to (hardware) signals
15 \fBtrap\fR [\fIargument\fR \fIn\fR [\fIn2\fR]...]
21 \fBonintr\fR [\fB-|\fR \fIlabel\fR]
27 \fB*trap\fR [\fIarg\fR \fIsig\fR [\fIsig2\fR...]]
33 \fB+trap\fR [\fB-p\fR] [\fIaction\fR \fIcondition\fR...]
40 The \fBtrap\fR command \fIargument\fR is to be read and executed when the shell
41 receives numeric or symbolic signal(s) (\fIn\fR). (Note: \fIargument\fR is
42 scanned once when the trap is set and once when the trap is taken.) Trap
43 commands are executed in order of signal number or corresponding symbolic
44 names. Any attempt to set a trap on a signal that was ignored on entry to the
45 current shell is ineffective. An attempt to trap on signal 11 (memory fault)
46 produces an error. If \fIargument\fR is absent all trap(s) \fIn\fR are reset to
47 their original values. If \fIargument\fR is the null string this signal is
48 ignored by the shell and by the commands it invokes. If \fIn\fR is \fB0\fR the
49 command \fIargument\fR is executed on exit from the shell. The \fBtrap\fR
50 command with no arguments prints a list of commands associated with each signal
55 \fBonintr\fR controls the action of the shell on interrupts. With no arguments,
56 \fBonintr\fR restores the default action of the shell on interrupts. (The shell
57 terminates shell scripts and returns to the terminal command input level). With
58 the \fB\(mi\fR argument, the shell ignores all interrupts. With a \fIlabel\fR
59 argument, the shell executes a \fBgoto\fR \fIlabel\fR when an interrupt is
60 received or a child process terminates because it was interrupted.
64 \fBtrap\fR uses \fIarg\fR as a command to be read and executed when the shell
65 receives signal(s) \fIsig\fR. \fIarg\fR is scanned once when the trap is set
66 and once when the trap is taken. Each \fIsig\fR can be specified as a number or
67 as the name of the signal. \fBtrap\fR commands are executed in order of signal
68 number. Any attempt to set a trap on a signal that was ignored on entry to the
69 current shell is ineffective. If \fIarg\fR is omitted or is \fB\(mi\fR, then
70 the trap(s) for each \fIsig\fR are reset to their original values. If \fIarg\fR
71 is the null (the empty string, for example, \fB""\fR) string then this signal
72 is ignored by the shell and by the commands it invokes. If \fIsig\fR is
73 \fBERR\fR then \fIarg\fR are executed whenever a command has a non-zero exit
74 status. If \fIsig\fR is \fBDEBUG\fR then \fIarg\fR are executed after each
75 command. If \fIsig\fR is \fB0\fR or \fBEXIT\fR for a \fBtrap\fR set outside any
76 function then the command \fIarg\fR is executed on exit from the shell. The
77 \fBtrap\fR command with no arguments prints a list of commands associated with
81 On this manual page, \fBksh\fR(1) commands that are preceded by one or two *
82 (asterisks) are treated specially in the following ways:
86 Variable assignment lists preceding the command remain in effect when the
92 I/O redirections are processed after variable assignments.
97 Errors cause a script that contains them to abort.
102 Words, following a command preceded by ** that are in the format of a
103 variable assignment, are expanded with the same rules as a variable assignment.
104 This means that tilde substitution is performed after the \fB=\fR sign and word
105 splitting and file name generation are not performed.
110 \fBtrap\fR is a special built-in that defines actions to be taken when
111 conditions such as receiving a signal occur. \fBtrap\fR can also be used to
112 display the current trap settings on standard output.
115 If \fIaction\fR is \fB-\fR, \fBtrap\fR resets each condition to the default
116 value. If \fIaction\fR is an empty string, the shell ignores each of the
117 conditions if they arise. Otherwise, the argument \fIaction\fR is read and
118 executed by the shell as if it were processed by \fBeval\fR when one of the
119 corresponding conditions arise. The action of the trap overrides any previous
120 action associated with each specified condition. The value of \fB$?\fR is not
121 altered by the trap execution.
124 \fIcondition\fR can be the name or number of a signal, or one of the following:
131 Execute this trap when the shell exits. If defined within a function with the
132 \fBfunction\fR reserved word, executes the trap in the caller's environment
133 when the function returns. The trap action is restored to the value it had when
134 it called the function.
152 Execute before each simple command is executed but after the arguments are
162 Execute whenever \fBset -e\fR would cause the shell to exit.
171 Execute when a key is entered from a terminal device.
176 Signal names are case insensitive and the \fBsig\fR prefix is optional. Signals
177 that were ignored on entry to a non-interactive shell cannot trapped or reset
178 although doing so does not report an error. The use of signal numbers other
179 than 1, 2, 3, 6, 9, 14, and 15 are not portable.
182 Although trap is a special built-in, specifying a condition that the shell does
183 not know about causes trap to exit with a \fBnon-zero\fR exit status, but does
184 not terminate the invoking shell.
187 If no action or conditions are specified then all the current trap settings are
188 written to standard output.
191 The following options are supported by the \fBtrap\fR built-in command in
199 Causes the current traps to be output in a format that can be processed as
200 input to the shell to recreate the current traps.
205 The trap built-in in \fBksh93\fR exits with one of the following values:
212 Successful completion.
226 On this manual page, \fBksh93\fR(1) commands that are preceded by one or two
227 \fB+\fR (plus signs) are treated specially in the following ways:
231 Variable assignment lists preceding the command remain in effect when the
237 I/O redirections are processed after variable assignments.
242 Errors cause a script that contains them to abort.
247 They are not valid function names.
252 Words, following a command preceded by \fB++\fR that are in the format of a
253 variable assignment, are expanded with the same rules as a variable assignment.
254 This means that tilde substitution is performed after the \fB=\fR sign and word
255 splitting and file name generation are not performed.
260 \fBcsh\fR(1), \fBeval\fR(1), \fBexit\fR(1), \fBksh\fR(1), \fBksh93\fR(1),
261 \fBsh\fR(1), \fBattributes\fR(5)