Files
2024-02-19 00:21:47 -05:00

1230 lines
62 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>sh</title>
</head>
<body bgcolor="white">
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
</script>
<basefont size="3"> <a name="sh"></a> <a name="tag_04_128"></a><!-- sh -->
<!--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_128_01"></a>NAME</h4>
<blockquote>sh - shell, the standard command language interpreter</blockquote>
<h4><a name="tag_04_128_02"></a>SYNOPSIS</h4>
<blockquote class="synopsis">
<p><code><tt>sh</tt> <b>[</b><tt>-abCefhimnuvx</tt><b>][</b><tt>-o</tt> <i>option</i><b>][</b><tt>+abCefhimnuvx</tt><b>][</b><tt>+o</tt>
<i>option</i><b>]<br>
</b> <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt> <b>[</b><i>command_file</i> <b>[</b><i>argument</i><tt>...</tt><b>]]</b><tt><br>
<br>
sh -c</tt><b>[</b><tt>-abCefhimnuvx</tt><b>][</b><tt>-o</tt> <i>option</i><b>][</b><tt>+abCefhimnuvx</tt><b>][</b><tt>+o</tt>
<i>option</i><b>]</b><i>command_string<br>
</i> <tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt> <i></i><b>[</b><i>command_name</i>
<b>[</b><i>argument</i><tt>...</tt><b>]]</b><tt><br>
<br>
sh -s</tt><b>[</b><tt>-abCefhimnuvx</tt><b>][</b><tt>-o</tt> <i>option</i><b>][</b><tt>+abCefhimnuvx</tt><b>][</b><tt>+o</tt>
<i>option</i><b>][</b><i>argument</i><b>]</b><tt><br>
</tt></code></p>
</blockquote>
<h4><a name="tag_04_128_03"></a>DESCRIPTION</h4>
<blockquote>
<p>The <i>sh</i> utility is a command language interpreter that shall execute commands read from a command line string, the
standard input, or a specified file. The application shall ensure that the commands to be executed are expressed in the language
described in <a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> .</p>
<p>Pathname expansion shall not fail due to the size of a file.</p>
<p>Shell input and output redirections have an implementation-defined offset maximum that is established in the open file
description.</p>
</blockquote>
<h4><a name="tag_04_128_04"></a>OPTIONS</h4>
<blockquote>
<p>The <i>sh</i> utility shall conform to the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>, with an extension for support of a leading
plus sign ( <tt>'+'</tt> ) as noted below.</p>
<p>The <b>-a</b>, <b>-b</b>, <b>-C</b>, <b>-e</b>, <b>-f</b>, <b>-m</b>, <b>-n</b>, <b>-o</b> <i>option</i>, <b>-u</b>, <b>-v</b>,
and <b>-x</b> options are described as part of the <a href="../utilities/set.html"><i>set</i></a> utility in <a href=
"xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a> . The option letters derived from the <a href=
"../utilities/set.html"><i>set</i></a> special built-in shall also be accepted with a leading plus sign ( <tt>'+'</tt> )
instead of a leading hyphen (meaning the reverse case of the option as described in this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001).</p>
<p>The following additional options shall be supported:</p>
<dl compact>
<dt><b>-c</b></dt>
<dd>Read commands from the <i>command_string</i> operand. Set the value of special parameter 0 (see <a href=
"xcu_chap02.html#tag_02_05_02"><i>Special Parameters</i></a> ) from the value of the <i>command_name</i> operand and the positional
parameters ($1, $2, and so on) in sequence from the remaining <i>argument</i> operands. No commands shall be read from the standard
input.</dd>
<dt><b>-i</b></dt>
<dd>Specify that the shell is <i>interactive</i>; see below. An implementation may treat specifying the <b>-i</b> option as an
error if the real user ID of the calling process does not equal the effective user ID or if the real group ID does not equal the
effective group ID.</dd>
<dt><b>-s</b></dt>
<dd>Read commands from the standard input.</dd>
</dl>
<p>If there are no operands and the <b>-c</b> option is not specified, the <b>-s</b> option shall be assumed.</p>
<p>If the <b>-i</b> option is present, or if there are no operands and the shell's standard input and standard error are attached
to a terminal, the shell is considered to be <i>interactive</i>.</p>
</blockquote>
<h4><a name="tag_04_128_05"></a>OPERANDS</h4>
<blockquote>
<p>The following operands shall be supported:</p>
<dl compact>
<dt><tt>-</tt></dt>
<dd>A single hyphen shall be treated as the first operand and then ignored. If both <tt>'-'</tt> and <tt>"--"</tt> are given as
arguments, or if other operands precede the single hyphen, the results are undefined.</dd>
<dt><i>argument</i></dt>
<dd>The positional parameters ($1, $2, and so on) shall be set to <i>arguments</i>, if any.</dd>
<dt><i>command_file</i></dt>
<dd>The pathname of a file containing commands. If the pathname contains one or more slash characters, the implementation attempts
to read that file; the file need not be executable. If the pathname does not contain a slash character:
<ul>
<li>
<p>The implementation shall attempt to read that file from the current working directory; the file need not be executable.</p>
</li>
<li>
<p>If the file is not in the current working directory, the implementation may perform a search for an executable file using the
value of <i>PATH ,</i> as described in <a href="xcu_chap02.html#tag_02_09_01_01"><i>Command Search and Execution</i></a> .</p>
</li>
</ul>
<p>Special parameter 0 (see <a href="xcu_chap02.html#tag_02_05_02"><i>Special Parameters</i></a> ) shall be set to the value of
<i>command_file</i>. If <i>sh</i> is called using a synopsis form that omits <i>command_file</i>, special parameter 0 shall be set
to the value of the first argument passed to <i>sh</i> from its parent (for example, <i>argv</i>[0] for a C program), which is
normally a pathname used to execute the <i>sh</i> utility.</p>
</dd>
<dt><i>command_name</i></dt>
<dd><br>
A string assigned to special parameter 0 when executing the commands in <i>command_string</i>. If <i>command_name</i> is not
specified, special parameter 0 shall be set to the value of the first argument passed to <i>sh</i> from its parent (for example,
<i>argv</i>[0] for a C program), which is normally a pathname used to execute the <i>sh</i> utility.</dd>
<dt><i>command_string</i></dt>
<dd><br>
A string that shall be interpreted by the shell as one or more commands, as if the string were the argument to the <a href=
"../functions/system.html"><i>system</i>()</a> function defined in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001.
If the <i>command_string</i> operand is an empty string, <i>sh</i> shall exit with a zero exit status.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_128_06"></a>STDIN</h4>
<blockquote>
<p>The standard input shall be used only if one of the following is true:</p>
<ul>
<li>
<p>The <b>-s</b> option is specified.</p>
</li>
<li>
<p>The <b>-c</b> option is not specified and no operands are specified.</p>
</li>
<li>
<p>The script executes one or more commands that require input from standard input (such as a <a href=
"../utilities/read.html"><i>read</i></a> command that does not redirect its input).</p>
</li>
</ul>
<p>See the INPUT FILES section.</p>
<p>When the shell is using standard input and it invokes a command that also uses standard input, the shell shall ensure that the
standard input file pointer points directly after the command it has read when the command begins execution. It shall not read
ahead in such a manner that any characters intended to be read by the invoked command are consumed by the shell (whether
interpreted by the shell or not) or that characters that are not read by the invoked command are not seen by the shell. When the
command expecting to read standard input is started asynchronously by an interactive shell, it is unspecified whether characters
are read by the command or interpreted by the shell.</p>
<p>If the standard input to <i>sh</i> is a FIFO or terminal device and is set to non-blocking reads, then <i>sh</i> shall enable
blocking reads on standard input. This shall remain in effect when the command completes.</p>
</blockquote>
<h4><a name="tag_04_128_07"></a>INPUT FILES</h4>
<blockquote>
<p>The input file shall be a text file, except that line lengths shall be unlimited. If the input file is empty or consists solely
of blank lines or comments, or both, <i>sh</i> shall exit with a zero exit status.</p>
</blockquote>
<h4><a name="tag_04_128_08"></a>ENVIRONMENT VARIABLES</h4>
<blockquote>
<p>The following environment variables shall affect the execution of <i>sh</i>:</p>
<dl compact>
<dt><i>ENV</i></dt>
<dd>This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see <a href=
"xcu_chap02.html#tag_02_06_02"><i>Parameter Expansion</i></a> ) by the shell, and the resulting value shall be used as a pathname
of a file containing shell commands to execute in the current environment. The file need not be executable. If the expanded value
of <i>ENV</i> is not an absolute pathname, the results are unspecified. <i>ENV</i> shall be ignored if the real and effective user
IDs or real and effective group IDs of the process are different.</dd>
<dt><i>FCEDIT</i></dt>
<dd>This variable, when expanded by the shell, shall determine the default value for the <b>-e</b> <i>editor</i> option's
<i>editor</i> option-argument. If <i>FCEDIT</i> is null or unset, <a href="../utilities/ed.html"><i>ed</i></a> shall be used as the
editor. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of this variable only for systems supporting the User
Portability Utilities option.</dd>
<dt><i>HISTFILE</i></dt>
<dd>Determine a pathname naming a command history file. If the <i>HISTFILE</i> variable is not set, the shell may attempt to access
or create a file <b>.sh_history</b> in the directory referred to by the <i>HOME</i> environment variable. If the shell cannot
obtain both read and write access to, or create, the history file, it shall use an unspecified mechanism that allows the history to
operate properly. (References to history &quot;file&quot; in this section shall be understood to mean this unspecified mechanism in such
cases.) An implementation may choose to access this variable only when initializing the history file; this initialization shall
occur when <a href="../utilities/fc.html"><i>fc</i></a> or <i>sh</i> first attempt to retrieve entries from, or add entries to, the
file, as the result of commands issued by the user, the file named by the <i>ENV</i> variable, or implementation-defined system
start-up files. Implementations may choose to disable the history list mechanism for users with appropriate privileges who do not
set <i>HISTFILE ;</i> the specific circumstances under which this occurs are implementation-defined. If more than one instance of
the shell is using the same history file, it is unspecified how updates to the history file from those shells interact. As entries
are deleted from the history file, they shall be deleted oldest first. It is unspecified when history file entries are physically
removed from the history file. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of this variable only for
systems supporting the User Portability Utilities option.</dd>
<dt><i>HISTSIZE</i></dt>
<dd>Determine a decimal number representing the limit to the number of previous commands that are accessible. If this variable is
unset, an unspecified default greater than or equal to 128 shall be used. The maximum number of commands in the history list is
unspecified, but shall be at least 128. An implementation may choose to access this variable only when initializing the history
file, as described under <i>HISTFILE .</i> Therefore, it is unspecified whether changes made to <i>HISTSIZE</i> after the history
file has been initialized are effective.</dd>
<dt><i>HOME</i></dt>
<dd>Determine the pathname of the user's home directory. The contents of <i>HOME</i> are used in tilde expansion as described in <a
href="xcu_chap02.html#tag_02_06_01"><i>Tilde Expansion</i></a> . This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the
effects of this variable only for systems supporting the User Portability Utilities option.</dd>
<dt><i>IFS</i></dt>
<dd>(Input Field Separators.) A string treated as a list of characters that shall be used for field splitting and to split lines
into words with the <a href="../utilities/read.html"><i>read</i></a> command. See <a href="xcu_chap02.html#tag_02_06_05"><i>Field
Splitting</i></a> . If <i>IFS</i> is not set, the shell shall behave as if the value of <i>IFS</i> were &lt;space&gt;, &lt;tab&gt;,
and &lt;newline&gt;. Implementations may ignore the value of <i>IFS</i> in the environment at the time <i>sh</i> is invoked,
treating <i>IFS</i> as if it were not set.</dd>
<dt><i>LANG</i></dt>
<dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume of
IEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> for
the precedence of internationalization variables used to determine the values of locale categories.)</dd>
<dt><i>LC_ALL</i></dt>
<dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd>
<dt><i>LC_COLLATE</i></dt>
<dd><br>
Determine the behavior of range expressions, equivalence classes, and multi-character collating elements within pattern
matching.</dd>
<dt><i>LC_CTYPE</i></dt>
<dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte as
opposed to multi-byte characters in arguments and input files), which characters are defined as letters (character class
<b>alpha</b>), and the behavior of character classes within pattern matching.</dd>
<dt><i>LC_MESSAGES</i></dt>
<dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard
error.</dd>
<dt><i>MAIL</i></dt>
<dd>Determine a pathname of the user's mailbox file for purposes of incoming mail notification. If this variable is set, the shell
shall inform the user if the file named by the variable is created or if its modification time has changed. Informing the user
shall be accomplished by writing a string of unspecified format to standard error prior to the writing of the next primary prompt
string. Such check shall be performed only after the completion of the interval defined by the <i>MAILCHECK</i> variable after the
last such check. The user shall be informed only if <i>MAIL</i> is set and <i>MAILPATH</i> is not set. This volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of this variable only for systems supporting the User Portability Utilities
option.</dd>
<dt><i>MAILCHECK</i></dt>
<dd><br>
Establish a decimal integer value that specifies how often (in seconds) the shell shall check for the arrival of mail in the files
specified by the <i>MAILPATH</i> or <i>MAIL</i> variables. The default value shall be 600 seconds. If set to zero, the shell shall
check before issuing each primary prompt. This volume of IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of this variable only
for systems supporting the User Portability Utilities option.</dd>
<dt><i>MAILPATH</i></dt>
<dd>Provide a list of pathnames and optional messages separated by colons. If this variable is set, the shell shall inform the user
if any of the files named by the variable are created or if any of their modification times change. (See the preceding entry for
<i>MAIL</i> for descriptions of mail arrival and user informing.) Each pathname can be followed by <tt>'%'</tt> and a string that
shall be subjected to parameter expansion and written to standard error when the modification time changes. If a <tt>'%'</tt>
character in the pathname is preceded by a backslash, it shall be treated as a literal <tt>'%'</tt> in the pathname. The default
message is unspecified.
<p>The <i>MAILPATH</i> environment variable takes precedence over the <i>MAIL</i> variable. This volume of
IEEE&nbsp;Std&nbsp;1003.1-2001 specifies the effects of this variable only for systems supporting the User Portability Utilities
option.</p>
</dd>
<dt><i>NLSPATH</i></dt>
<dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt=
"[Option End]" border="0"></dd>
<dt><i>PATH</i></dt>
<dd>Establish a string formatted as described in the Base Definitions volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>, used to effect command interpretation; see <a href=
"xcu_chap02.html#tag_02_09_01_01"><i>Command Search and Execution</i></a> .</dd>
<dt><i>PWD</i></dt>
<dd>This variable shall represent an absolute pathname of the current working directory. Assignments to this variable may be
ignored unless the value is an absolute pathname of the current working directory and there are no filename components of dot or
dot-dot.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_128_09"></a>ASYNCHRONOUS EVENTS</h4>
<blockquote>
<p>Default.</p>
</blockquote>
<h4><a name="tag_04_128_10"></a>STDOUT</h4>
<blockquote>
<p>See the STDERR section.</p>
</blockquote>
<h4><a name="tag_04_128_11"></a>STDERR</h4>
<blockquote>
<p>Except as otherwise stated (by the descriptions of any invoked utilities or in interactive mode), standard error shall be used
only for diagnostic messages.</p>
</blockquote>
<h4><a name="tag_04_128_12"></a>OUTPUT FILES</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_128_13"></a>EXTENDED DESCRIPTION</h4>
<blockquote>
<p>See <a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> . The following additional capabilities are supported on
systems supporting the User Portability Utilities option.</p>
<h5><a name="tag_04_128_13_01"></a>Command History List</h5>
<p>When the <i>sh</i> utility is being used interactively, it shall maintain a list of commands previously entered from the
terminal in the file named by the <i>HISTFILE</i> environment variable. The type, size, and internal format of this file are
unspecified. Multiple <i>sh</i> processes can share access to the file for a user, if file access permissions allow this; see the
description of the <i>HISTFILE</i> environment variable.</p>
<h5><a name="tag_04_128_13_02"></a>Command Line Editing</h5>
<p>When <i>sh</i> is being used interactively from a terminal, the current command and the command history (see <a href=
"fc.html"><i>fc</i></a> ) can be edited using <a href="../utilities/vi.html"><i>vi</i></a>-mode command line editing. This mode
uses commands, described below, similar to a subset of those described in the <a href="../utilities/vi.html"><i>vi</i></a> utility.
Implementations may offer other command line editing modes corresponding to other editing utilities.</p>
<p>The command <a href="../utilities/set.html"><i>set</i></a> <b>-o</b> <a href="../utilities/vi.html"><i>vi</i></a>
shall enable <a href="../utilities/vi.html"><i>vi</i></a>-mode editing and place <i>sh</i> into <a href=
"../utilities/vi.html"><i>vi</i></a> insert mode (see <a href="#tag_04_128_13_03">Command Line Editing (vi-mode)</a> ). This
command also shall disable any other editing mode that the implementation may provide. The command <a href=
"../utilities/set.html"><i>set</i></a> <b>+o</b> <a href="../utilities/vi.html"><i>vi</i></a> disables <a href=
"../utilities/vi.html"><i>vi</i></a>-mode editing.</p>
<p>Certain block-mode terminals may be unable to support shell command line editing. If a terminal is unable to provide either edit
mode, it need not be possible to <a href="../utilities/set.html"><i>set</i></a> <b>-o</b> <a href=
"../utilities/vi.html"><i>vi</i></a> when using the shell on this terminal.</p>
<p>In the following sections, the characters <i>erase</i>, <i>interrupt</i>, <i>kill</i>, and <i>end-of-file</i> are those set by
the <a href="../utilities/stty.html"><i>stty</i></a> utility.</p>
<h5><a name="tag_04_128_13_03"></a>Command Line Editing (vi-mode)</h5>
<p>In <a href="../utilities/vi.html"><i>vi</i></a> editing mode, there shall be a distinguished line, the edit line. All the
editing operations which modify a line affect the edit line. The edit line is always the newest line in the command history
buffer.</p>
<p>With <a href="../utilities/vi.html"><i>vi</i></a>-mode enabled, <i>sh</i> can be switched between insert mode and command
mode.</p>
<p>When in insert mode, an entered character shall be inserted into the command line, except as noted in <a href=
"#tag_04_128_13_04">vi Line Editing Insert Mode</a> . Upon entering <i>sh</i> and after termination of the previous command,
<i>sh</i> shall be in insert mode.</p>
<p>Typing an escape character shall switch <i>sh</i> into command mode (see <a href="#tag_04_128_13_05">vi Line Editing Command
Mode</a> ). In command mode, an entered character shall either invoke a defined operation, be used as part of a multi-character
operation, or be treated as an error. A character that is not recognized as part of an editing command shall terminate any specific
editing command and shall alert the terminal. Typing the <i>interrupt</i> character in command mode shall cause <i>sh</i> to
terminate command line editing on the current command line, reissue the prompt on the next line of the terminal, and reset the
command history (see <a href="fc.html"><i>fc</i></a> ) so that the most recently executed command is the previous command (that is,
the command that was being edited when it was interrupted is not reentered into the history).</p>
<p>In the following sections, the phrase &quot;move the cursor to the beginning of the word&quot; shall mean &quot;move the cursor to the first
character of the current word&quot; and the phrase &quot;move the cursor to the end of the word&quot; shall mean &quot;move the cursor to the last
character of the current word&quot;. The phrase &quot;beginning of the command line&quot; indicates the point between the end of the prompt
string issued by the shell (or the beginning of the terminal line, if there is no prompt string) and the first character of the
command text.</p>
<h5><a name="tag_04_128_13_04"></a>vi Line Editing Insert Mode</h5>
<p>While in insert mode, any character typed shall be inserted in the current command line, unless it is from the following
set.</p>
<dl compact>
<dt>&lt;newline&gt;</dt>
<dd>Execute the current command line. If the current command line is not empty, this line shall be entered into the command history
(see <a href="fc.html"><i>fc</i></a> ).</dd>
<dt><i>erase</i></dt>
<dd>Delete the character previous to the current cursor position and move the current cursor position back one character. In insert
mode, characters shall be erased from both the screen and the buffer when backspacing.</dd>
<dt><i>interrupt</i></dt>
<dd>Terminate command line editing with the same effects as described for interrupting command mode; see <a href=
"#tag_04_128_13_03">Command Line Editing (vi-mode)</a> .</dd>
<dt><i>kill</i></dt>
<dd>Clear all the characters from the input line.</dd>
<dt>&lt;control&gt;-V</dt>
<dd>Insert the next character input, even if the character is otherwise a special insert mode character.</dd>
<dt>&lt;control&gt;-W</dt>
<dd>Delete the characters from the one preceding the cursor to the preceding word boundary. The word boundary in this case is the
closer to the cursor of either the beginning of the line or a character that is in neither the <b>blank</b> nor <b>punct</b>
character classification of the current locale.</dd>
<dt><i>end-of-file</i></dt>
<dd>Interpreted as the end of input in <i>sh</i>. This interpretation shall occur only at the beginning of an input line. If
<i>end-of-file</i> is entered other than at the beginning of the line, the results are unspecified.</dd>
<dt>&lt;ESC&gt;</dt>
<dd>Place <i>sh</i> into command mode.</dd>
</dl>
<h5><a name="tag_04_128_13_05"></a>vi Line Editing Command Mode</h5>
<p>In command mode for the command line editing feature, decimal digits not beginning with 0 that precede a command letter shall be
remembered. Some commands use these decimal digits as a count number that affects the operation.</p>
<p>The term <i>motion command</i> represents one of the commands:</p>
<pre>
<tt>&lt;space&gt; 0 b F l W ^ $ ; E f T w | , B e h t
</tt>
</pre>
<p>If the current line is not the edit line, any command that modifies the current line shall cause the content of the current line
to replace the content of the edit line, and the current line shall become the edit line. This replacement cannot be undone (see
the <b>u</b> and <b>U</b> commands below). The modification requested shall then be performed to the edit line. When the current
line is the edit line, the modification shall be done directly to the edit line.</p>
<p>Any command that is preceded by <i>count</i> shall take a count (the numeric value of any preceding decimal digits). Unless
otherwise noted, this count shall cause the specified operation to repeat by the number of times specified by the count. Also
unless otherwise noted, a <i>count</i> that is out of range is considered an error condition and shall alert the terminal, but
neither the cursor position, nor the command line, shall change.</p>
<p>The terms <i>word</i> and <i>bigword</i> are used as defined in the <a href="../utilities/vi.html"><i>vi</i></a> description.
The term <i>save buffer</i> corresponds to the term <i>unnamed buffer</i> in <a href="../utilities/vi.html"><i>vi</i></a>.</p>
<p>The following commands shall be recognized in command mode:</p>
<dl compact>
<dt>&lt;newline&gt;</dt>
<dd>Execute the current command line. If the current command line is not empty, this line shall be entered into the command history
(see <a href="fc.html"><i>fc</i></a> ).</dd>
<dt>&lt;control&gt;-L</dt>
<dd>Redraw the current command line. Position the cursor at the same location on the redrawn line.</dd>
<dt><b>#</b></dt>
<dd>Insert the character <tt>'#'</tt> at the beginning of the current command line and treat the resulting edit line as a comment.
This line shall be entered into the command history; see <a href="fc.html"><i>fc</i></a> .</dd>
<dt><b>=</b></dt>
<dd>Display the possible shell word expansions (see <a href="xcu_chap02.html#tag_02_06"><i>Word Expansions</i></a> ) of the bigword
at the current command line position. <basefont size="2">
<dl>
<dt><b>Note:</b></dt>
<dd>This does not modify the content of the current line, and therefore does not cause the current line to become the edit
line.</dd>
</dl>
<basefont size="3">
<p>These expansions shall be displayed on subsequent terminal lines. If the bigword contains none of the characters <tt>'?'</tt> ,
<tt>'*'</tt> , or <tt>'['</tt> , an asterisk ( <tt>'*'</tt> ) shall be implicitly assumed at the end. If any directories are
matched, these expansions shall have a <tt>'/'</tt> character appended. After the expansion, the line shall be redrawn, the cursor
repositioned at the current cursor position, and <i>sh</i> shall be placed in command mode.</p>
</dd>
<dt><b>\</b></dt>
<dd>Perform pathname expansion (see <a href="xcu_chap02.html#tag_02_06_06"><i>Pathname Expansion</i></a> ) on the current bigword,
up to the largest set of characters that can be matched uniquely. If the bigword contains none of the characters <tt>'?'</tt> ,
<tt>'*'</tt> , or <tt>'['</tt> , an asterisk ( <tt>'*'</tt> ) shall be implicitly assumed at the end. This maximal expansion then
shall replace the original bigword in the command line, and the cursor shall be placed after this expansion. If the resulting
bigword completely and uniquely matches a directory, a <tt>'/'</tt> character shall be inserted directly after the bigword. If some
other file is completely matched, a single &lt;space&gt; shall be inserted after the bigword. After this operation, <i>sh</i> shall
be placed in insert mode.</dd>
<dt><b>*</b></dt>
<dd>Perform pathname expansion on the current bigword and insert all expansions into the command to replace the current bigword,
with each expansion separated by a single &lt;space&gt;. If at the end of the line, the current cursor position shall be moved to
the first column position following the expansions and <i>sh</i> shall be placed in insert mode. Otherwise, the current cursor
position shall be the last column position of the first character after the expansions and <i>sh</i> shall be placed in insert
mode. If the current bigword contains none of the characters <tt>'?'</tt> , <tt>'*'</tt> , or <tt>'['</tt> , before the operation,
an asterisk shall be implicitly assumed at the end.</dd>
<dt><b>@</b><i>letter</i></dt>
<dd>Insert the value of the alias named <i>_letter</i>. The symbol <i>letter</i> represents a single alphabetic character from the
portable character set; implementations may support additional characters as an extension. If the alias <i>_letter</i> contains
other editing commands, these commands shall be performed as part of the insertion. If no alias <i>_letter</i> is enabled, this
command shall have no effect.</dd>
<dt><b>[</b><i>count</i><b>]&#152;</b></dt>
<dd>Convert, if the current character is a lowercase letter, to the equivalent uppercase letter and <i>vice versa</i>, as
prescribed by the current locale. The current cursor position then shall be advanced by one character. If the cursor was positioned
on the last character of the line, the case conversion shall occur, but the cursor shall not advance. If the <tt>'&#152;'</tt>
command is preceded by a <i>count</i>, that number of characters shall be converted, and the cursor shall be advanced to the
character position after the last character converted. If the <i>count</i> is larger than the number of characters after the
cursor, this shall not be considered an error; the cursor shall advance to the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>].</b></dt>
<dd>Repeat the most recent non-motion command, even if it was executed on an earlier command line. If the previous command was
preceded by a <i>count</i>, and no count is given on the <tt>'.'</tt> command, the count from the previous command shall be
included as part of the repeated command. If the <tt>'.'</tt> command is preceded by a <i>count</i>, this shall override any
<i>count</i> argument to the previous command. The <i>count</i> specified in the <tt>'.'</tt> command shall become the count for
subsequent <tt>'.'</tt> commands issued without a count.</dd>
<dt><b>[</b><i>number</i><b>]v</b></dt>
<dd>Invoke the <a href="../utilities/vi.html"><i>vi</i></a> editor to edit the current command line in a temporary file. When the
editor exits, the commands in the temporary file shall be executed and placed in the command history. If a <i>number</i> is
included, it specifies the command number in the command history to be edited, rather than the current command line.</dd>
<dt><b>[</b><i>count</i><b>]l</b>&nbsp;&nbsp;&nbsp;(ell)</dt>
<dt><b>[</b><i>count</i><b>]</b>&lt;space&gt;</dt>
<dd><br>
Move the current cursor position to the next character position. If the cursor was positioned on the last character of the line,
the terminal shall be alerted and the cursor shall not be advanced. If the <i>count</i> is larger than the number of characters
after the cursor, this shall not be considered an error; the cursor shall advance to the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>]h</b></dt>
<dd>Move the current cursor position to the <i>count</i>th (default 1) previous character position. If the cursor was positioned on
the first character of the line, the terminal shall be alerted and the cursor shall not be moved. If the count is larger than the
number of characters before the cursor, this shall not be considered an error; the cursor shall move to the first character on the
line.</dd>
<dt><b>[</b><i>count</i><b>]w</b></dt>
<dd>Move to the start of the next word. If the cursor was positioned on the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the <i>count</i> is larger than the number of words after the cursor, this shall
not be considered an error; the cursor shall advance to the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>]W</b></dt>
<dd>Move to the start of the next bigword. If the cursor was positioned on the last character of the line, the terminal shall be
alerted and the cursor shall not be advanced. If the <i>count</i> is larger than the number of bigwords after the cursor, this
shall not be considered an error; the cursor shall advance to the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>]e</b></dt>
<dd>Move to the end of the current word. If at the end of a word, move to the end of the next word. If the cursor was positioned on
the last character of the line, the terminal shall be alerted and the cursor shall not be advanced. If the <i>count</i> is larger
than the number of words after the cursor, this shall not be considered an error; the cursor shall advance to the last character on
the line.</dd>
<dt><b>[</b><i>count</i><b>]E</b></dt>
<dd>Move to the end of the current bigword. If at the end of a bigword, move to the end of the next bigword. If the cursor was
positioned on the last character of the line, the terminal shall be alerted and the cursor shall not be advanced. If the
<i>count</i> is larger than the number of bigwords after the cursor, this shall not be considered an error; the cursor shall
advance to the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>]b</b></dt>
<dd>Move to the beginning of the current word. If at the beginning of a word, move to the beginning of the previous word. If the
cursor was positioned on the first character of the line, the terminal shall be alerted and the cursor shall not be moved. If the
<i>count</i> is larger than the number of words preceding the cursor, this shall not be considered an error; the cursor shall
return to the first character on the line.</dd>
<dt><b>[</b><i>count</i><b>]B</b></dt>
<dd>Move to the beginning of the current bigword. If at the beginning of a bigword, move to the beginning of the previous bigword.
If the cursor was positioned on the first character of the line, the terminal shall be alerted and the cursor shall not be moved.
If the <i>count</i> is larger than the number of bigwords preceding the cursor, this shall not be considered an error; the cursor
shall return to the first character on the line.</dd>
<dt><b>^</b></dt>
<dd>Move the current cursor position to the first character on the input line that is not a &lt;blank&gt;.</dd>
<dt><b>$</b></dt>
<dd>Move to the last character position on the current command line.</dd>
<dt><b>0</b></dt>
<dd>(Zero.) Move to the first character position on the current command line.</dd>
<dt><b>[</b><i>count</i><b>]|</b></dt>
<dd>Move to the <i>count</i>th character position on the current command line. If no number is specified, move to the first
position. The first character position shall be numbered 1. If the count is larger than the number of characters on the line, this
shall not be considered an error; the cursor shall be placed on the last character on the line.</dd>
<dt><b>[</b><i>count</i><b>]f</b><i>c</i></dt>
<dd>Move to the first occurrence of the character <tt>'c'</tt> that occurs after the current cursor position. If the cursor was
positioned on the last character of the line, the terminal shall be alerted and the cursor shall not be advanced. If the character
<tt>'c'</tt> does not occur in the line after the current cursor position, the terminal shall be alerted and the cursor shall not
be moved.</dd>
<dt><b>[</b><i>count</i><b>]F</b><i>c</i></dt>
<dd>Move to the first occurrence of the character <tt>'c'</tt> that occurs before the current cursor position. If the cursor was
positioned on the first character of the line, the terminal shall be alerted and the cursor shall not be moved. If the character
<tt>'c'</tt> does not occur in the line before the current cursor position, the terminal shall be alerted and the cursor shall not
be moved.</dd>
<dt><b>[</b><i>count</i><b>]t</b><i>c</i></dt>
<dd>Move to the character before the first occurrence of the character <tt>'c'</tt> that occurs after the current cursor position.
If the cursor was positioned on the last character of the line, the terminal shall be alerted and the cursor shall not be advanced.
If the character <tt>'c'</tt> does not occur in the line after the current cursor position, the terminal shall be alerted and the
cursor shall not be moved.</dd>
<dt><b>[</b><i>count</i><b>]T</b><i>c</i></dt>
<dd>Move to the character after the first occurrence of the character <tt>'c'</tt> that occurs before the current cursor position.
If the cursor was positioned on the first character of the line, the terminal shall be alerted and the cursor shall not be moved.
If the character <tt>'c'</tt> does not occur in the line before the current cursor position, the terminal shall be alerted and the
cursor shall not be moved.</dd>
<dt><b>[</b><i>count</i><b>];</b></dt>
<dd>Repeat the most recent <b>f</b>, <b>F</b>, <b>t</b>, or <b>T</b> command. Any number argument on that previous command shall be
ignored. Errors are those described for the repeated command.</dd>
<dt><b>[</b><i>count</i><b>],</b></dt>
<dd>Repeat the most recent <b>f</b>, <b>F</b>, <b>t</b>, or <b>T</b> command. Any number argument on that previous command shall be
ignored. However, reverse the direction of that command.</dd>
<dt><b>a</b></dt>
<dd>Enter insert mode after the current cursor position. Characters that are entered shall be inserted before the next
character.</dd>
<dt><b>A</b></dt>
<dd>Enter insert mode after the end of the current command line.</dd>
<dt><b>i</b></dt>
<dd>Enter insert mode at the current cursor position. Characters that are entered shall be inserted before the current
character.</dd>
<dt><b>I</b></dt>
<dd>Enter insert mode at the beginning of the current command line.</dd>
<dt><b>R</b></dt>
<dd>Enter insert mode, replacing characters from the command line beginning at the current cursor position.</dd>
<dt><b>[</b><i>count</i><b>]c</b><i>motion</i></dt>
<dd><br>
Delete the characters between the current cursor position and the cursor position that would result from the specified motion
command. Then enter insert mode before the first character following any deleted characters. If <i>count</i> is specified, it shall
be applied to the motion command. A <i>count</i> shall be ignored for the following motion commands:
<pre>
<tt>0 ^ $ c
</tt>
</pre>
<p>If the motion command is the character <tt>'c'</tt> , the current command line shall be cleared and insert mode shall be
entered. If the motion command would move the current cursor position toward the beginning of the command line, the character under
the current cursor position shall not be deleted. If the motion command would move the current cursor position toward the end of
the command line, the character under the current cursor position shall be deleted. If the <i>count</i> is larger than the number
of characters between the current cursor position and the end of the command line toward which the motion command would move the
cursor, this shall not be considered an error; all of the remaining characters in the aforementioned range shall be deleted and
insert mode shall be entered. If the motion command is invalid, the terminal shall be alerted, the cursor shall not be moved, and
no text shall be deleted.</p>
</dd>
<dt><b>C</b></dt>
<dd>Delete from the current character to the end of the line and enter insert mode at the new end-of-line.</dd>
<dt><b>S</b></dt>
<dd>Clear the entire edit line and enter insert mode.</dd>
<dt><b>[</b><i>count</i><b>]r</b><i>c</i></dt>
<dd>Replace the current character with the character <tt>'c'</tt> . With a number <i>count</i>, replace the current and the
following <i>count</i>-1 characters. After this command, the current cursor position shall be on the last character that was
changed. If the <i>count</i> is larger than the number of characters after the cursor, this shall not be considered an error; all
of the remaining characters shall be changed.</dd>
<dt><b>[</b><i>count</i><b>]_</b></dt>
<dd>Append a &lt;space&gt; after the current character position and then append the last bigword in the previous input line after
the &lt;space&gt;. Then enter insert mode after the last character just appended. With a number <i>count</i>, append the
<i>count</i>th bigword in the previous line.</dd>
<dt><b>[</b><i>count</i><b>]x</b></dt>
<dd>Delete the character at the current cursor position and place the deleted characters in the save buffer. If the cursor was
positioned on the last character of the line, the character shall be deleted and the cursor position shall be moved to the previous
character (the new last character). If the <i>count</i> is larger than the number of characters after the cursor, this shall not be
considered an error; all the characters from the cursor to the end of the line shall be deleted.</dd>
<dt><b>[</b><i>count</i><b>]X</b></dt>
<dd>Delete the character before the current cursor position and place the deleted characters in the save buffer. The character
under the current cursor position shall not change. If the cursor was positioned on the first character of the line, the terminal
shall be alerted, and the <b>X</b> command shall have no effect. If the line contained a single character, the <b>X</b> command
shall have no effect. If the line contained no characters, the terminal shall be alerted and the cursor shall not be moved. If the
<i>count</i> is larger than the number of characters before the cursor, this shall not be considered an error; all the characters
from before the cursor to the beginning of the line shall be deleted.</dd>
<dt><b>[</b><i>count</i><b>]d</b><i>motion</i></dt>
<dd><br>
Delete the characters between the current cursor position and the character position that would result from the motion command. A
number <i>count</i> repeats the motion command <i>count</i> times. If the motion command would move toward the beginning of the
command line, the character under the current cursor position shall not be deleted. If the motion command is <b>d</b>, the entire
current command line shall be cleared. If the <i>count</i> is larger than the number of characters between the current cursor
position and the end of the command line toward which the motion command would move the cursor, this shall not be considered an
error; all of the remaining characters in the aforementioned range shall be deleted. The deleted characters shall be placed in the
save buffer.</dd>
<dt><b>D</b></dt>
<dd>Delete all characters from the current cursor position to the end of the line. The deleted characters shall be placed in the
save buffer.</dd>
<dt><b>[</b><i>count</i><b>]y</b><i>motion</i></dt>
<dd><br>
Yank (that is, copy) the characters from the current cursor position to the position resulting from the motion command into the
save buffer. A number <i>count</i> shall be applied to the motion command. If the motion command would move toward the beginning of
the command line, the character under the current cursor position shall not be included in the set of yanked characters. If the
motion command is <b>y</b>, the entire current command line shall be yanked into the save buffer. The current cursor position shall
be unchanged. If the <i>count</i> is larger than the number of characters between the current cursor position and the end of the
command line toward which the motion command would move the cursor, this shall not be considered an error; all of the remaining
characters in the aforementioned range shall be yanked.</dd>
<dt><b>Y</b></dt>
<dd>Yank the characters from the current cursor position to the end of the line into the save buffer. The current character
position shall be unchanged.</dd>
<dt><b>[</b><i>count</i><b>]p</b></dt>
<dd>Put a copy of the current contents of the save buffer after the current cursor position. The current cursor position shall be
advanced to the last character put from the save buffer. A <i>count</i> shall indicate how many copies of the save buffer shall be
put.</dd>
<dt><b>[</b><i>count</i><b>]P</b></dt>
<dd>Put a copy of the current contents of the save buffer before the current cursor position. The current cursor position shall be
moved to the last character put from the save buffer. A <i>count</i> shall indicate how many copies of the save buffer shall be
put.</dd>
<dt><b>u</b></dt>
<dd>Undo the last command that changed the edit line. This operation shall not undo the copy of any command line to the edit
line.</dd>
<dt><b>U</b></dt>
<dd>Undo all changes made to the edit line. This operation shall not undo the copy of any command line to the edit line.</dd>
<dt><b>[</b><i>count</i><b>]k</b></dt>
<dt><b>[</b><i>count</i><b>]-</b></dt>
<dd>Set the current command line to be the <i>count</i>th previous command line in the shell command history. If <i>count</i> is
not specified, it shall default to 1. The cursor shall be positioned on the first character of the new command. If a <b>k</b> or
<b>-</b> command would retreat past the maximum number of commands in effect for this shell (affected by the <i>HISTSIZE</i>
environment variable), the terminal shall be alerted, and the command shall have no effect.</dd>
<dt><b>[</b><i>count</i><b>]j</b></dt>
<dt><b>[</b><i>count</i><b>]+</b></dt>
<dd>Set the current command line to be the <i>count</i>th next command line in the shell command history. If <i>count</i> is not
specified, it shall default to 1. The cursor shall be positioned on the first character of the new command. If a <b>j</b> or
<b>+</b> command advances past the edit line, the current command line shall be restored to the edit line and the terminal shall be
alerted.</dd>
<dt><b>[</b><i>number</i><b>]G</b></dt>
<dd>Set the current command line to be the oldest command line stored in the shell command history. With a number <i>number</i>,
set the current command line to be the command line <i>number</i> in the history. If command line <i>number</i> does not exist, the
terminal shall be alerted and the command line shall not be changed.</dd>
<dt><b>/</b><i>pattern</i>&lt;newline&gt;</dt>
<dd><br>
Move backwards through the command history, searching for the specified pattern, beginning with the previous command line. Patterns
use the pattern matching notation described in <a href="xcu_chap02.html#tag_02_13"><i>Pattern Matching Notation</i></a> , except
that the <tt>'^'</tt> character shall have special meaning when it appears as the first character of <i>pattern</i>. In this case,
the <tt>'^'</tt> is discarded and the characters after the <tt>'^'</tt> shall be matched only at the beginning of a line. Commands
in the command history shall be treated as strings, not as filenames. If the pattern is not found, the current command line shall
be unchanged and the terminal is alerted. If it is found in a previous line, the current command line shall be set to that line and
the cursor shall be set to the first character of the new command line.
<p>If <i>pattern</i> is empty, the last non-empty pattern provided to <b>/</b> or <b>?</b> shall be used. If there is no previous
non-empty pattern, the terminal shall be alerted and the current command line shall remain unchanged.</p>
</dd>
<dt><b>?</b><i>pattern</i>&lt;newline&gt;</dt>
<dd><br>
Move forwards through the command history, searching for the specified pattern, beginning with the next command line. Patterns use
the pattern matching notation described in <a href="xcu_chap02.html#tag_02_13"><i>Pattern Matching Notation</i></a> , except that
the <tt>'^'</tt> character shall have special meaning when it appears as the first character of <i>pattern</i>. In this case, the
<tt>'^'</tt> is discarded and the characters after the <tt>'^'</tt> shall be matched only at the beginning of a line. Commands in
the command history shall be treated as strings, not as filenames. If the pattern is not found, the current command line shall be
unchanged and the terminal alerted. If it is found in a following line, the current command line shall be set to that line and the
cursor shall be set to the fist character of the new command line.
<p>If <i>pattern</i> is empty, the last non-empty pattern provided to <b>/</b> or <b>?</b> shall be used. If there is no previous
non-empty pattern, the terminal shall be alerted and the current command line shall remain unchanged.</p>
</dd>
<dt><b>n</b></dt>
<dd>Repeat the most recent <b>/</b> or <b>?</b> command. If there is no previous <b>/</b> or <b>?</b>, the terminal shall be
alerted and the current command line shall remain unchanged.</dd>
<dt><b>N</b></dt>
<dd>Repeat the most recent <b>/</b> or <b>?</b> command, reversing the direction of the search. If there is no previous <b>/</b> or
<b>?</b>, the terminal shall be alerted and the current command line shall remain unchanged.</dd>
</dl>
</blockquote>
<h4><a name="tag_04_128_14"></a>EXIT STATUS</h4>
<blockquote>
<p>The following exit values shall be returned:</p>
<dl compact>
<dt>&nbsp;&nbsp;&nbsp;&nbsp;0</dt>
<dd>The script to be executed consisted solely of zero or more blank lines or comments, or both.</dd>
<dt>1-125</dt>
<dd>A non-interactive shell detected a syntax, redirection, or variable assignment error.</dd>
<dt>&nbsp;&nbsp;127</dt>
<dd>A specified <i>command_file</i> could not be found by a non-interactive shell.</dd>
</dl>
<p>Otherwise, the shell shall return the exit status of the last command it invoked or attempted to invoke (see also the <a href=
"../utilities/exit.html"><i>exit</i></a> utility in <a href="xcu_chap02.html#tag_02_14"><i>Special Built-In
Utilities</i></a> ).</p>
</blockquote>
<h4><a name="tag_04_128_15"></a>CONSEQUENCES OF ERRORS</h4>
<blockquote>
<p>See <a href="xcu_chap02.html#tag_02_08_01"><i>Consequences of Shell Errors</i></a> .</p>
</blockquote>
<hr>
<div class="box"><em>The following sections are informative.</em></div>
<h4><a name="tag_04_128_16"></a>APPLICATION USAGE</h4>
<blockquote>
<p>Standard input and standard error are the files that determine whether a shell is interactive when <b>-i</b> is not specified.
For example:</p>
<pre>
<tt>sh &gt; file
</tt>
</pre>
<p>and:</p>
<pre>
<tt>sh 2&gt; file
</tt>
</pre>
<p>create interactive and non-interactive shells, respectively. Although both accept terminal input, the results of error
conditions are different, as described in <a href="xcu_chap02.html#tag_02_08_01"><i>Consequences of Shell Errors</i></a> ; in the
second example a redirection error encountered by a special built-in utility aborts the shell.</p>
<p>A conforming application must protect its first operand, if it starts with a plus sign, by preceding it with the <tt>"--"</tt>
argument that denotes the end of the options.</p>
<p>Applications should note that the standard <i>PATH</i> to the shell cannot be assumed to be either <b>/bin/sh</b> or
<b>/usr/bin/sh</b>, and should be determined by interrogation of the <i>PATH</i> returned by <a href=
"../utilities/getconf.html"><i>getconf</i></a> <i>PATH ,</i> ensuring that the returned pathname is an absolute pathname and not a
shell built-in.</p>
<p>For example, to determine the location of the standard <i>sh</i> utility:</p>
<pre>
<tt>command -v sh
</tt>
</pre>
<p>On some implementations this might return:</p>
<pre>
<tt>/usr/xpg4/bin/sh
</tt>
</pre>
<p>Furthermore, on systems that support executable scripts (the <tt>"#!"</tt> construct), it is recommended that applications using
executable scripts install them using <a href="../utilities/getconf.html"><i>getconf</i></a> <b>-v</b> to determine the shell
pathname and update the <tt>"#!"</tt> script appropriately as it is being installed (for example, with <a href=
"../utilities/sed.html"><i>sed</i></a>). For example:</p>
<pre>
<tt>#
# Installation time script to install correct POSIX shell pathname
#
# Get list of paths to check
#
Sifs=$IFS
IFS=:
set $(getconf PATH)
IFS=$Sifs
#
# Check each path for 'sh'
#
for i in $@
do
if [ -f ${i}/sh ];
then
Pshell=${i}/sh
fi
done
#
# This is the list of scripts to update. They should be of the
# form '${name}.source' and will be transformed to '${name}'.
# Each script should begin:
#
# !INSTALLSHELLPATH -p
#
scripts="a b c"
#
# Transform each script
#
for i in ${scripts}
do
sed -e "s|INSTALLSHELLPATH|${Pshell}|" &lt; ${i}.source &gt; ${i}
done
</tt>
</pre>
</blockquote>
<h4><a name="tag_04_128_17"></a>EXAMPLES</h4>
<blockquote>
<ol>
<li>
<p>Execute a shell command from a string:</p>
<pre>
<tt>sh -c "cat myfile"
</tt>
</pre>
</li>
<li>
<p>Execute a shell script from a file in the current directory:</p>
<pre>
<tt>sh my_shell_cmds
</tt>
</pre>
</li>
</ol>
</blockquote>
<h4><a name="tag_04_128_18"></a>RATIONALE</h4>
<blockquote>
<p>The <i>sh</i> utility and the <a href="../utilities/set.html"><i>set</i></a> special built-in utility share a common
set of options.</p>
<p>The KornShell ignores the contents of <i>IFS</i> upon entry to the script. A conforming application cannot rely on importing
<i>IFS .</i> One justification for this, beyond security considerations, is to assist possible future shell compilers. Allowing
<i>IFS</i> to be imported from the environment prevents many optimizations that might otherwise be performed via dataflow analysis
of the script itself.</p>
<p>The text in the STDIN section about non-blocking reads concerns an instance of <i>sh</i> that has been invoked, probably by a
C-language program, with standard input that has been opened using the O_NONBLOCK flag; see <a href=
"../functions/open.html"><i>open</i>()</a> in the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001. If the shell did not
reset this flag, it would immediately terminate because no input data would be available yet and that would be considered the same
as end-of-file.</p>
<p>The options associated with a <i>restricted shell</i> (command name <i>rsh</i> and the <b>-r</b> option) were excluded because
the standard developers considered that the implied level of security could not be achieved and they did not want to raise false
expectations.</p>
<p>On systems that support set-user-ID scripts, a historical trapdoor has been to link a script to the name <b>-i</b>. When it is
called by a sequence such as:</p>
<pre>
<tt>sh -
</tt>
</pre>
<p>or by:</p>
<pre>
<tt>#! usr/bin/sh -
</tt>
</pre>
<p>the historical systems have assumed that no option letters follow. Thus, this volume of IEEE&nbsp;Std&nbsp;1003.1-2001 allows
the single hyphen to mark the end of the options, in addition to the use of the regular <tt>"--"</tt> argument, because it was
considered that the older practice was so pervasive. An alternative approach is taken by the KornShell, where real and effective
user/group IDs must match for an interactive shell; this behavior is specifically allowed by this volume of
IEEE&nbsp;Std&nbsp;1003.1-2001. <basefont size="2"></p>
<dl>
<dt><b>Note:</b></dt>
<dd>There are other problems with set-user-ID scripts that the two approaches described here do not resolve.</dd>
</dl>
<basefont size="3">
<p>The initialization process for the history file can be dependent on the system start-up files, in that they may contain commands
that effectively preempt the user's settings of <i>HISTFILE</i> and <i>HISTSIZE .</i> For example, function definition commands are
recorded in the history file, unless the <a href="../utilities/set.html"><i>set</i></a> <b>-o</b> <i>nolog</i> option is
set. If the system administrator includes function definitions in some system start-up file called before the <i>ENV</i> file, the
history file is initialized before the user gets a chance to influence its characteristics. In some historical shells, the history
file is initialized just after the <i>ENV</i> file has been processed. Therefore, it is implementation-defined whether changes made
to <i>HISTFILE</i> after the history file has been initialized are effective.</p>
<p>The default messages for the various <i>MAIL -related</i> messages are unspecified because they vary across implementations.
Typical messages are:</p>
<pre>
<tt>"you have mail\n"
</tt>
</pre>
<p>or:</p>
<pre>
<tt>"you have new mail\n"
</tt>
</pre>
<p>It is important that the descriptions of command line editing refer to the same shell as that in IEEE&nbsp;Std&nbsp;1003.1-2001
so that interactive users can also be application programmers without having to deal with programmatic differences in their two
environments. It is also essential that the utility name <i>sh</i> be specified because this explicit utility name is too firmly
rooted in historical practice of application programs for it to change.</p>
<p>Consideration was given to mandating a diagnostic message when attempting to set <a href=
"../utilities/vi.html"><i>vi</i></a>-mode on terminals that do not support command line editing. However, it is not historical
practice for the shell to be cognizant of all terminal types and thus be able to detect inappropriate terminals in all cases.
Implementations are encouraged to supply diagnostics in this case whenever possible, rather than leaving the user in a state where
editing commands work incorrectly.</p>
<p>In early proposals, the KornShell-derived <i>emacs</i> mode of command line editing was included, even though the <i>emacs</i>
editor itself was not. The community of <i>emacs</i> proponents was adamant that the full <i>emacs</i> editor not be standardized
because they were concerned that an attempt to standardize this very powerful environment would encourage vendors to ship strictly
conforming versions lacking the extensibility required by the community. The author of the original <i>emacs</i> program also
expressed his desire to omit the program. Furthermore, there were a number of historical systems that did not include <i>emacs</i>,
or included it without supporting it, but there were very few that did not include and support <a href=
"../utilities/vi.html"><i>vi</i></a>. The shell <i>emacs</i> command line editing mode was finally omitted because it became
apparent that the KornShell version and the editor being distributed with the GNU system had diverged in some respects. The author
of <i>emacs</i> requested that the POSIX <i>emacs</i> mode either be deleted or have a significant number of unspecified
conditions. Although the KornShell author agreed to consider changes to bring the shell into alignment, the standard developers
decided to defer specification at that time. At the time, it was assumed that convergence on an acceptable definition would occur
for a subsequent draft, but that has not happened, and there appears to be no impetus to do so. In any case, implementations are
free to offer additional command line editing modes based on the exact models of editors their users are most comfortable with.</p>
<p>Early proposals had the following list entry in <a href="#tag_04_128_13_04">vi Line Editing Insert Mode</a> :</p>
<dl compact>
<dt><tt>\</tt></dt>
<dd>If followed by the <i>erase</i> or <i>kill</i> character, that character shall be inserted into the input line. Otherwise, the
backslash itself shall be inserted into the input line.</dd>
</dl>
<p>However, this is not actually a feature of <i>sh</i> command line editing insert mode, but one of some historical terminal line
drivers. Some conforming implementations continue to do this when the <a href="../utilities/stty.html"><i>stty</i></a>
<b>iexten</b> flag is set.</p>
</blockquote>
<h4><a name="tag_04_128_19"></a>FUTURE DIRECTIONS</h4>
<blockquote>
<p>None.</p>
</blockquote>
<h4><a name="tag_04_128_20"></a>SEE ALSO</h4>
<blockquote>
<p><a href="xcu_chap02.html#tag_02"><i>Shell Command Language</i></a> , <a href="cd.html"><i>cd</i></a> , <a href=
"echo.html"><i>echo</i></a> , <a href="exit.html#tag_04_47"><i>exit</i>()</a> , <a href="fc.html"><i>fc</i></a> , <a href=
"pwd.html"><i>pwd</i></a> , <a href="read.html"><i>read</i>()</a> , <a href="set.html#tag_04_127"><i>set</i></a> , <a href=
"stty.html"><i>stty</i></a> , <a href="test.html"><i>test</i></a> , <a href="umask.html"><i>umask</i>()</a> , <a href=
"vi.html"><i>vi</i></a> , the System Interfaces volume of IEEE&nbsp;Std&nbsp;1003.1-2001, <a href=
"../functions/dup.html"><i>dup</i>()</a>, <i>exec</i>, <a href="../functions/exit.html"><i>exit</i>()</a>, <a href=
"../functions/fork.html"><i>fork</i>()</a>, <a href="../functions/open.html"><i>open</i>()</a>, <a href=
"../functions/pipe.html"><i>pipe</i>()</a>, <a href="../functions/signal.html"><i>signal</i>()</a>, <a href=
"../functions/system.html"><i>system</i>()</a>, <a href="../functions/ulimit.html"><i>ulimit</i>()</a>, <a href=
"../functions/umask.html"><i>umask</i>()</a>, <a href="../functions/wait.html"><i>wait</i>()</a></p>
</blockquote>
<h4><a name="tag_04_128_21"></a>CHANGE HISTORY</h4>
<blockquote>
<p>First released in Issue 2.</p>
</blockquote>
<h4><a name="tag_04_128_22"></a>Issue 5</h4>
<blockquote>
<p>The FUTURE DIRECTIONS section is added.</p>
<p>Text is added to the DESCRIPTION for the Large File Summit proposal.</p>
</blockquote>
<h4><a name="tag_04_128_23"></a>Issue 6</h4>
<blockquote>
<p>The Open Group Corrigendum U029/2 is applied, correcting the second SYNOPSIS.</p>
<p>The Open Group Corrigendum U027/3 is applied, correcting a typographical error.</p>
<p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p>
<ul>
<li>
<p>The option letters derived from the <a href="../utilities/set.html"><i>set</i></a> special built-in are also accepted
with a leading plus sign ( <tt>'+'</tt> ).</p>
</li>
<li>
<p>Large file extensions are added:</p>
<ul>
<li>
<p>Pathname expansion does not fail due to the size of a file.</p>
</li>
<li>
<p>Shell input and output redirections have an implementation-defined offset maximum that is established in the open file
description.</p>
</li>
</ul>
</li>
</ul>
<p>In the ENVIRONMENT VARIABLES section, the text &quot;user's home directory&quot; is updated to &quot;directory referred to by the
<i>HOME</i> environment variable&quot;.</p>
<p>Descriptions for the <i>ENV</i> and <i>PWD</i> environment variables are included to align with the IEEE&nbsp;P1003.2b draft
standard.</p>
<p>The normative text is reworded to avoid use of the term &quot;must&quot; for application requirements.</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>