📄 sh.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-2003 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, 2003 Edition<br>Copyright © 2001-2003 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> </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> </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, thestandard input, or a specified file. The application shall ensure that the commands to be executed are expressed in the languagedescribed 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 filedescription.</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 Std 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 leadingplus 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 ofIEEE Std 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 positionalparameters ($1, $2, and so on) in sequence from the remaining <i>argument</i> operands. No commands shall be read from the standardinput.</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 anerror 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 theeffective 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 attachedto 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 asarguments, 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 attemptsto 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 thevalue 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 setto 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 isnormally 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 notspecified, 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 Std 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 thestandard input file pointer points directly after the command it has read when the command begins execution. It shall not readahead in such a manner that any characters intended to be read by the invoked command are consumed by the shell (whetherinterpreted by the shell or not) or that characters that are not read by the invoked command are not seen by the shell. When thecommand expecting to read standard input is started asynchronously by an interactive shell, it is unspecified whether charactersare 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 enableblocking 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 solelyof 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 pathnameof a file containing shell commands to execute in the current environment. The file need not be executable. If the expanded valueof <i>ENV</i> is not an absolute pathname, the results are unspecified. <i>ENV</i> shall be ignored if the real and effective userIDs 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 theeditor. This volume of IEEE Std 1003.1-2001 specifies the effects of this variable only for systems supporting the UserPortability 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 accessor create a file <b>.sh_history</b> in the directory referred to by the <i>HOME</i> environment variable. If the shell cannotobtain both read and write access to, or create, the history file, it shall use an unspecified mechanism that allows the history tooperate properly. (References to history "file" in this section shall be understood to mean this unspecified mechanism in suchcases.) An implementation may choose to access this variable only when initializing the history file; this initialization shalloccur when <a href="../utilities/fc.html"><i>fc</i></a> or <i>sh</i> first attempt to retrieve entries from, or add entries to, thefile, as the result of commands issued by the user, the file named by the <i>ENV</i> variable, or implementation-defined systemstart-up files. Implementations may choose to disable the history list mechanism for users with appropriate privileges who do notset <i>HISTFILE ;</i> the specific circumstances under which this occurs are implementation-defined. If more than one instance ofthe shell is using the same history file, it is unspecified how updates to the history file from those shells interact. As entriesare deleted from the history file, they shall be deleted oldest first. It is unspecified when history file entries are physicallyremoved from the history file. This volume of IEEE Std 1003.1-2001 specifies the effects of this variable only forsystems 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 isunset, an unspecified default greater than or equal to 128 shall be used. The maximum number of commands in the history list isunspecified, but shall be at least 128. An implementation may choose to access this variable only when initializing the historyfile, as described under <i>HISTFILE .</i> Therefore, it is unspecified whether changes made to <i>HISTSIZE</i> after the historyfile 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 <ahref="xcu_chap02.html#tag_02_06_01"><i>Tilde Expansion</i></a> . This volume of IEEE Std 1003.1-2001 specifies theeffects 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 linesinto words with the <a href="../utilities/read.html"><i>read</i></a> command. See <a href="xcu_chap02.html#tag_02_06_05"><i>FieldSplitting</i></a> . If <i>IFS</i> is not set, the shell shall behave as if the value of <i>IFS</i> were <space>, <tab>,and <newline>. Implementations may ignore the value of <i>IFS</i> in the environment at the time <i>sh</i> is invoked,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -