Files
oldlinux-files/Ref-docs/POSIX/susv3/utilities/exec.html
2024-02-19 00:21:47 -05:00

217 lines
5.5 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 -->
<!-- Copyright (c) 2001 The Open Group, All Rights Reserved -->
<title>exec</title>
</head>
<body bgcolor="white">
<basefont size="3"> <a name="exec"></a> <a name="tag_04_46"></a><!-- exec -->
<!--header start-->
<center><font size="2">The Open Group Base Specifications Issue 6<br>
IEEE Std 1003.1-2001<br>
Copyright &copy; 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
<!--header end-->
<hr size="2" noshade>
<h4><a name="tag_04_46_01"></a>NAME</h4>
<blockquote>exec - execute commands and open, close, or copy file descriptors</blockquote>
<h4><a name="tag_04_46_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>exec</tt> <b>[</b><i>command</i> <b>[</b><i>argument</i> <tt>...</tt><b>]]</b></code></p>
</blockquote>
<h4><a name="tag_04_46_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>exec</i> utility shall open, close, and/or copy file descriptors as specified by any redirections as part of the
command.</p>
<p>If <i>exec</i> is specified without <i>command</i> or <i>argument</i>s, and any file descriptors with numbers greater than 2 are
opened with associated redirection statements, it is unspecified whether those file descriptors remain open when the shell invokes
another utility. Scripts concerned that child shells could misuse open file descriptors can always close them explicitly, as shown
in one of the following examples.</p>
<p>If <i>exec</i> is specified with <i>command</i>, it shall replace the shell with <i>command</i> without creating a new process.
If <i>argument</i>s are specified, they shall be arguments to <i>command</i>. Redirection affects the current shell execution
environment.</p>
</blockquote>
<h4><a name="tag_04_46_04"></a>OPTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_05"></a>OPERANDS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_06"></a>STDIN</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_07"></a>INPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_10"></a>STDOUT</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_11"></a>STDERR</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_14"></a>EXIT STATUS</h4>
<blockquote>
<p>If <i>command</i> is specified, <i>exec</i> shall not return to the shell; rather, the exit status of the process shall be the
exit status of the program implementing <i>command</i>, which overlaid the shell. If <i>command</i> is not found, the exit status
shall be 127. If <i>command</i> is found, but it is not an executable utility, the exit status shall be 126. If a redirection error
occurs (see <a href="xcu_chap02.html#tag_02_08_01"><i>Consequences of Shell Errors</i></a> ), the shell shall exit with a value in
the range 1-125. Otherwise, <i>exec</i> shall return a zero exit status.</p>
</blockquote>
<h4><a name="tag_04_46_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_46_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_17"></a>EXAMPLES</h4>
<blockquote>
<p>Open <i>readfile</i> as file descriptor 3 for reading:</p>
<pre>
<tt>exec 3&lt; readfile
</tt>
</pre>
<p>Open <i>writefile</i> as file descriptor 4 for writing:</p>
<pre>
<tt>exec 4&gt; writefile
</tt>
</pre>
<p>Make file descriptor 5 a copy of file descriptor 0:</p>
<pre>
<tt>exec 5&lt;&amp;0
</tt>
</pre>
<p>Close file descriptor 3:</p>
<pre>
<tt>exec 3&lt;&amp;-
</tt>
</pre>
<p>Cat the file <b>maggie</b> by replacing the current shell with the <a href="../utilities/cat.html"><i>cat</i></a> utility:</p>
<pre>
<tt>exec cat maggie
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_46_18"></a>RATIONALE</h4>
<blockquote>
<p>Most historical implementations were not conformant in that:</p>
<pre>
<tt>foo=bar exec cmd
</tt>
</pre>
<p>did not pass <b>foo</b> to <b>cmd</b>.</p>
</blockquote>
<h4><a name="tag_04_46_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_46_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a></p>
</blockquote>
<h4><a name="tag_04_46_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>None.</p>
</blockquote>
<div class="box"><em>End of informative text.</em></div>
<hr>
<hr size="2" noshade>
<center><font size="2"><!--footer start-->
UNIX &reg; is a registered Trademark of The Open Group.<br>
POSIX &reg; is a registered Trademark of The IEEE.<br>
[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href=
"../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>
]</font></center>
<!--footer end-->
<hr size="2" noshade>
</body>
</html>