155 lines
3.6 KiB
HTML
155 lines
3.6 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
<html>
|
|
<head>
|
|
<meta name="generator" content="HTML Tidy, see www.w3.org">
|
|
<meta http-equiv="Content-Type" content=
|
|
"text/html; charset=utf-8">
|
|
<title>trap - Trap signals</title>
|
|
<LINK rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
|
</HEAD>
|
|
<body bgcolor="#FFFFFF">
|
|
<!-- Java sync-link -->
|
|
<SCRIPT LANGUAGE="Javascript" SRC="../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
|
|
|
|
|
|
|
|
<h2>trap - Trap signals</h2>
|
|
|
|
<strong>Synopsis</strong>
|
|
|
|
<p><strong>trap</strong> [ <em>action condition</em> ... ]</p>
|
|
|
|
<p><strong>trap -p</strong> [ <em>condition</em> ... ]</p>
|
|
|
|
<p>
|
|
<strong>trap -l</strong>
|
|
</p>
|
|
|
|
<p><strong>Description</strong></p>
|
|
|
|
<p>The <strong>trap</strong> utility sets the <em>action</em>
|
|
for <strong>qsh</strong> to take when a <em>condition</em> arises.
|
|
<strong>qsh</strong> expands <em>action</em> once when running
|
|
<strong>trap</strong> and again when <em>condition</em> arises.</p>
|
|
|
|
<p>When the <strong>-p</strong> option is specified, <strong>
|
|
trap</strong> displays the current <em>action</em> for the specified
|
|
<em>conditions</em>.</p>
|
|
|
|
<p>
|
|
When the <strong>-l</strong> option is specified,
|
|
<strong>trap</strong> displays a list of all of the signal names and their
|
|
corresponding numbers.
|
|
</p>
|
|
|
|
<p>When no arguments are specified, <strong>trap</strong> displays a list
|
|
of the currently defined traps.</p>
|
|
|
|
<p><strong>Options</strong></p>
|
|
|
|
<dl>
|
|
<dt>
|
|
<strong>-l</strong></dt>
|
|
|
|
<dd>Display a list of all of the signal names and their corresponding numbers.
|
|
</dd>
|
|
|
|
<dt><strong>-p</strong></dt>
|
|
|
|
<dd>Display each trap in a re-enterable format.</dd>
|
|
</dl>
|
|
|
|
<p><strong>Operands</strong></p>
|
|
|
|
<p>For <em>action</em>, you can specify:</p>
|
|
|
|
<ul>
|
|
<li>Null to ignore <em>condition</em> when it arises</li>
|
|
|
|
<li>Minus (<strong>-</strong>) to reset <em>condition</em> to its
|
|
original value.</li>
|
|
|
|
<li>A command to be run each time <em>condition</em> arises.</li>
|
|
</ul>
|
|
|
|
<p>For <em>condition,</em> you can specify:</p>
|
|
|
|
<ul>
|
|
<li>Name or number of a signal. You can use <strong>trap
|
|
-l</strong> to display a list of valid signals. For portability,
|
|
you should always specify the signal name.</li>
|
|
|
|
<li><strong>0</strong> or <strong>EXIT</strong>. <strong>
|
|
qsh</strong> runs <em>action</em> when the shell exits.</li>
|
|
|
|
<li><strong>ERR</strong>. <strong>qsh</strong> runs <em>action</em>
|
|
when a command has a non-zero exit status.</li>
|
|
|
|
<li><strong>DEBUG</strong>. <strong>qsh</strong> runs <em>
|
|
action</em> after each simple command.</li>
|
|
</ul>
|
|
|
|
<p>If more than one condition arises at the same time, <strong>
|
|
qsh</strong> runs the traps in this order:</p>
|
|
|
|
<ol>
|
|
<li><strong>DEBUG</strong>, if it is specified, then</li>
|
|
|
|
<li><strong>ERR</strong>, if it is specified and applicable,
|
|
then</li>
|
|
|
|
<li>Any other specified traps in signal number order, then</li>
|
|
|
|
<li><strong>EXIT</strong>.</li>
|
|
</ol>
|
|
|
|
<p><strong>Exit Status</strong></p>
|
|
|
|
<ul>
|
|
<li>0 when successful.</li>
|
|
|
|
<li>>0 when an invalid <em>condition</em> is specified.</li>
|
|
</ul>
|
|
|
|
<p><strong>Related information</strong></p>
|
|
|
|
<ul>
|
|
<li><a href="kill.htm">kill - Terminate or signal
|
|
processes</a></li>
|
|
|
|
<li><a href="wait.htm">wait - Wait for process completion</a></li>
|
|
</ul>
|
|
|
|
<strong>Examples</strong>
|
|
|
|
<ol>
|
|
<li>Set a trap for the ERR condition:
|
|
<pre>
|
|
trap `print Command failed' ERR
|
|
</pre></li>
|
|
|
|
<li>Ignore the ERR condition:
|
|
<pre>
|
|
trap "" ERR
|
|
</pre></li>
|
|
|
|
<li>Reset the ERR condition to its original value:
|
|
<pre>
|
|
trap - ERR
|
|
</pre></li>
|
|
|
|
<li>Display the current action for the ERR condition:
|
|
<pre>
|
|
trap -p ERR
|
|
</pre></li>
|
|
|
|
<li>Display all of the currently defined traps:
|
|
<pre>
|
|
trap
|
|
</pre></li>
|
|
</ol>
|
|
|
|
</body>
|
|
</html>
|
|
|