📄 sh.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>sh</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_1992"> </a>NAME</h4><blockquote>sh - shell, the standard command language interpreter</blockquote><h4><a name = "tag_001_014_1993"> </a>SYNOPSIS</h4><blockquote><pre><code>sh <b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>][</b><i>command_file </i><b>[</b><i>argument</i>...<b>]]</b>sh -c <b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>]</b><i>command_string</i><b>[</b><i>command_name </i><b>[</b><i>argument</i>...<b>]]</b>sh -s<b>[</b>-abCefimnuvx<b>][</b>-o <i>option</i><b>][</b>+abCefmnuvx<b>][</b>+o <i>option</i><b>][</b><i>argument</i><b>]</b></code></pre></blockquote><h4><a name = "tag_001_014_1994"> </a>DESCRIPTION</h4><blockquote>The<i>sh</i>utility is a command language interpreterthat executes commands read froma command-line string, the standard input or a specified file.The commands to be executed must beexpressed in the language described in<xref href=shell><a href="chap2.html#tag_001">Shell Command Language</a></xref>.<p>Pathname expansion will not fail due to the size of a file.<p>Shell input and output redirections will have animplementation-dependent offset maximum that will be established in theopen file description. </blockquote><h4><a name = "tag_001_014_1995"> </a>OPTIONS</h4><blockquote>The<i>sh</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b> </a> .<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>optionsare described as part of the<i>set</i>utility in<xref href=sbi><a href="chap2.html#tag_001_014">Special Built-in Utilities</a></xref>.The option letters derived from the<i>set</i>special built-in are also accepted with aleading plus sign(+)instead of a leading hyphen (meaning the reverse caseof the option as described in this specification).<p>The following additional options are supported:<dl compact><dt><b>-c</b><dd>Read commands from the<i>command_string</i>operand.Set the value of special parameter0(see<xref href=specpar><a href="chap2.html#tag_001_005_002">Special Parameters</a></xref>)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 will be read from the standard input.<dt><b>-i</b><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 IDof the calling process does not equal the effective user IDor if the real group ID does not equal the effective group ID.<dt><b>-s</b><dd>Read commands from the standard input.</dl><p>If there are no operands and the<b>-c</b>option is not specified, the<b>-s</b>option is assumed.<p>If the<b>-i</b>option is present, or if there are no operands andthe shell's standard input and standard error areattached to a terminal,the shell is considered to be<i>interactive .</i></blockquote><h4><a name = "tag_001_014_1996"> </a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><b>-</b><dd>A single hyphen is treated as the first operand and then ignored.If both "-" and--are given as arguments, or if other operands precede thesingle hyphen, the results are undefined.<dt><i>argument</i><dd>The positional parameters($1,$2and so on)will be set to<i>arguments</i>,if any.<dt><i>command_file</i><dd>The pathname of a file containing commands.If the pathname contains one or more slash characters,the implementation will attempt to read that file;the file need not be executable.If the pathname does not contain a slash character:<ul><li>The implementation will attempt to read thatfile from the current working directory;the file need not be executable.<li>If the file is not in the current working directory,the implementation may perform a search for an executable fileusing the value of<i>PATH ,</i>as described in<xref href=cmdsea><a href="chap2.html#tag_001_009_001_001">Command Search and Execution</a></xref>.</ul>Special parameter0(see<xref href=specpar><a href="chap2.html#tag_001_005_002">Special Parameters</a></xref>)is 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 parameter0is 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 normallya pathname used to execute the<i>sh</i>utility.<dt><i>command_name</i><dd>A string assigned to special parameter0when executing the commands in<i>command_string</i>.If<i>command_name</i>is not specified, special parameter0is 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.<dt><i>command_string</i><dd>A string that is interpreted by the shellas one or more commands, as if the string were the argument to the <b>XSH</b> specification<i><a href="../xsh/system.html">system()</a></i>function.If the<i>command_string</i>operand is an empty string,<i>sh</i>will exit with a zero exit status.</dl></blockquote><h4><a name = "tag_001_014_1997"> </a>STDIN</h4><blockquote>The standard input will be used only if one of the following is true:<ul><p><li>The<b>-s</b>option is specified.<p><li>The<b>-c</b>option is not specified and no operands are specified.<p><li>The script executes one or more commands that requireinput from standard input (such as a<i><a href="read.html">read</a></i>command that does not redirect its input).<p></ul><p>See the INPUT FILES section.<p>When the shell is using standard input and it invokes acommand that also uses standard input, the shellensures that the standard input file pointer pointsdirectly after the command it has read when the commandbegins execution.It will not read ahead in such a manner that any charactersintended to be read by the invoked command are consumed by theshell (whether interpreted by the shell or not) or that charactersthat are not read by the invoked command are not seen by the shell.When the command expecting to read standard inputis started asynchronously by an interactive shell,it is unspecified whether characters are read by thecommand or interpreted by the shell.<p>If the standard input to<i>sh</i>is a FIFO or terminal device andis set to non-blocking reads, then<i>sh</i>will enable blocking reads on standard input.This will remain in effect when the command completes.(This 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 theO_NONBLOCK flag; see<i><a href="../xsh/open.html">open()</a></i>in the <b>XSH</b> specification.If the shell did not reset this flag, it would immediatelyterminate because no input data would be available yetand that would be considered the same as end-of-file.)</blockquote><h4><a name = "tag_001_014_1998"> </a>INPUT FILES</h4><blockquote>The input file must be a text file,except that line lengths are unlimited.If the input file is empty or consists solely ofblank lines or comments, or both,<i>sh</i>will exit with a zero exit status.<br></blockquote><h4><a name = "tag_001_014_1999"> </a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>sh</i>:<dl compact><dt><i>FCEDIT</i><dd>This variable, when expanded by the shell,determines 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,<i><a href="ed.html">ed</a></i>will be used as the editor.<dt><i>HISTFILE</i><dd>Determine a pathname naming a command history file.If the<i>HISTFILE</i>variable is not set, theshell may attempt to access or create a file<b>.sh_history</b>in the user's home directory.If the shell cannotobtain both read and write access to,or create, the history file, itwill use an unspecified mechanism that allows the historyto operate properly.(References to history "file" in this sectionare understood to mean this unspecified mechanismin such cases.)An implementation may choose to access this variable only wheninitialising the history file;this initialisation will occur when<i><a href="fc.html">fc</a></i>or<i>sh</i>first attempt to retrieve entries from,or add entries to, the file, as the result ofcommands issued by the user, the file named by the<i>ENV</i>variable, or implementation-dependent system startup files.(The initialisation process for the history filecan be dependent on the system startup files, in thatthey may contain commands that will effectivelypreempt the user's settings of<i>HISTFILE</i>and<i>HISTSIZE .</i>For example, function definition commands are recordedin the history file, unless the<i>set</i><b>-o</b>nologoption is set.If the system administrator includes function definitionsin some system startup file called before the<i>ENV</i>file, the history file will be initialised beforethe user gets a chance to influence its characteristics.)In some historical shells, the history file is initialisedjust after the<i>ENV</i>file has been processed.Therefore, it is implementation-dependent whether changes made to<i>HISTFILE</i>after the history file has been initialised are effective.Implementations may choose to disable the history listmechanism for users with appropriate privileges who do not set<i>HISTFILE ;</i>the specific circumstances under which this will occur areimplementation-dependent.If more than one instance of the shell is using the same historyfile, it is unspecified how updates to the history file fromthose shells interact.As entries are deleted from the history file,they will be deleted oldest first.It is unspecified when history file entries arephysically removed from the history file.<dt><i>HISTSIZE</i><dd>Determine a decimal number representingthe limit to the number of previous commands that are accessible.If this variable is unset,an unspecified default greater than or equal to 128 will be used.The maximum number of commands in the history list is unspecified,but will be at least 128.An implementation may choose to access this variable only wheninitialising 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 initialised are effective.<dt><i>HOME</i><dd>Determine thepathname of the user's home directory.The contents of<i>HOME</i>are used in Tilde Expansion as described in<xref href=tildexp><a href="chap2.html#tag_001_006_001">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -