📄 xcu_chap02.html
字号:
</b></p></td><td align="left"><p class="tent"><b><br>esac<br> fi<br> for<br> if<br></b></p></td><td align="left"><p class="tent"><b><br>in<br> then<br> until<br> while<br></b></p></td></tr></table></blockquote><p>This recognition shall only occur when none of the characters is quoted and when the word is used as:</p><ul><li><p>The first word of a command</p></li><li><p>The first word following one of the reserved words other than <b>case</b>, <b>for</b>, or <b>in</b></p></li><li><p>The third word in a <b>case</b> command (only <b>in</b> is valid in this case)</p></li><li><p>The third word in a <b>for</b> command (only <b>in</b> and <b>do</b> are valid in this case)</p></li></ul><p>See the grammar in <a href="#tag_02_10">Shell Grammar</a> .</p><p>The following words may be recognized as reserved words on some implementations (when none of the characters are quoted),causing unspecified results:</p><blockquote><table cellpadding="3"><tr valign="top"><td align="left"><p class="tent"><b>[[</b></p></td><td align="left"><p class="tent"><b>]]</b></p></td><td align="left"><p class="tent"><b>function</b></p></td><td align="left"><p class="tent"><b>select</b></p></td></tr></table></blockquote><p>Words that are the concatenation of a name and a colon ( <tt>':'</tt> ) are reserved; their use produces unspecifiedresults.</p><h3><a name="tag_02_05"></a>Parameters and Variables</h3><p>A parameter can be denoted by a name, a number, or one of the special characters listed in <a href="#tag_02_05_02">SpecialParameters</a> . A variable is a parameter denoted by a name.</p><p>A parameter is set if it has an assigned value (null is a valid value). Once a variable is set, it can only be unset by usingthe <a href="unset.html"><i>unset</i></a> special built-in command.</p><h4><a name="tag_02_05_01"></a>Positional Parameters</h4><p>A positional parameter is a parameter denoted by the decimal value represented by one or more digits, other than the singledigit 0. The digits denoting the positional parameters shall always be interpreted as a decimal value, even if there is a leadingzero. When a positional parameter with more than one digit is specified, the application shall enclose the digits in braces (see <ahref="#tag_02_06_02">Parameter Expansion</a> ). Positional parameters are initially assigned when the shell is invoked (see <ahref="../utilities/sh.html"><i>sh</i></a>), temporarily replaced when a shell function is invoked (see <a href="#tag_02_09_05">Function Definition Command</a> ), and can be reassigned with the <a href="set.html"><i>set</i></a> special built-incommand.</p><h4><a name="tag_02_05_02"></a>Special Parameters</h4><p>Listed below are the special parameters and the values to which they shall expand. Only the values of the special parameters arelisted; see <a href="#tag_02_06">Word Expansions</a> for a detailed summary of all the stages involved in expanding words.</p><dl compact><dt><tt>@</tt></dt><dd>Expands to the positional parameters, starting from one. When the expansion occurs within double-quotes, and where fieldsplitting (see <a href="#tag_02_06_05">Field Splitting</a> ) is performed, each positional parameter shall expand as a separatefield, with the provision that the expansion of the first parameter shall still be joined with the beginning part of the originalword (assuming that the expanded parameter was embedded within a word), and the expansion of the last parameter shall still bejoined with the last part of the original word. If there are no positional parameters, the expansion of <tt>'@'</tt> shall generatezero fields, even when <tt>'@'</tt> is double-quoted.</dd><dt><tt>*</tt></dt><dd>Expands to the positional parameters, starting from one. When the expansion occurs within a double-quoted string (see <a href="#tag_02_02_03">Double-Quotes</a> ), it shall expand to a single field with the value of each parameter separated by the firstcharacter of the <i>IFS</i> variable, or by a <space> if <i>IFS</i> is unset. If <i>IFS</i> is set to a null string, this isnot equivalent to unsetting it; its first character does not exist, so the parameter values are concatenated.</dd><dt><tt>#</tt></dt><dd>Expands to the decimal number of positional parameters. The command name (parameter 0) shall not be counted in the number givenby <tt>'#'</tt> because it is a special parameter, not a positional parameter.</dd><dt><tt>?</tt></dt><dd>Expands to the decimal exit status of the most recent pipeline (see <a href="#tag_02_09_02">Pipelines</a> ).</dd><dt><tt>-</tt></dt><dd>(Hyphen.) Expands to the current option flags (the single-letter option names concatenated into a string) as specified oninvocation, by the <a href="set.html"><i>set</i></a> special built-in command, or implicitly by the shell.</dd><dt><tt>$</tt></dt><dd>Expands to the decimal process ID of the invoked shell. In a subshell (see <a href="#tag_02_12">Shell Execution Environment</a>), <tt>'$'</tt> shall expand to the same value as that of the current shell.</dd><dt><tt>!</tt></dt><dd>Expands to the decimal process ID of the most recent background command (see <a href="#tag_02_09_03">Lists</a> ) executed fromthe current shell. (For example, background commands executed from subshells do not affect the value of <tt>"$!"</tt> in thecurrent shell environment.) For a pipeline, the process ID is that of the last command in the pipeline.</dd><dt>0</dt><dd>(Zero.) Expands to the name of the shell or shell script. See <a href="sh.html"><i>sh</i></a> for a detailed description of howthis name is derived.</dd></dl><p>See the description of the <i>IFS</i> variable in <a href="#tag_02_05_03">Shell Variables</a> .</p><h4><a name="tag_02_05_03"></a>Shell Variables</h4><p>Variables shall be initialized from the environment (as defined by the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a> and the <i>exec</i>function in the System Interfaces volume of IEEE Std 1003.1-2001) and can be given new values with variable assignmentcommands. If a variable is initialized from the environment, it shall be marked for export immediately; see the <a href="export.html"><i>export</i></a> special built-in. New variables can be defined and initialized with variable assignments, with the <ahref="../utilities/read.html"><i>read</i></a> or <a href="../utilities/getopts.html"><i>getopts</i></a> utilities, with the<i>name</i> parameter in a <b>for</b> loop, with the ${ <i>name</i>= <i>word</i>} expansion, or with other mechanisms provided asimplementation extensions.</p><p>The following variables shall affect the execution of the shell:</p><dl compact><dt><i>ENV</i></dt><dd><sup>[<a href="javascript:open_code('UP XSI')">UP XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]"border="0"> The processing of the <i>ENV</i> shell variable shall be supported on all XSI-conformant systems or if the systemsupports the User Portability Utilities option. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> <p>This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see <a href="#tag_02_06_02">Parameter Expansion</a> ) by the shell and the resulting value shall be used as a pathname of a file containingshell commands to execute in the current environment. The file need not be executable. If the expanded value of <i>ENV</i> is notan absolute pathname, the results are unspecified. <i>ENV</i> shall be ignored if the user's real and effective user IDs or realand effective group IDs are different.</p></dd><dt><i>HOME</i></dt><dd>The pathname of the user's home directory. The contents of <i>HOME</i> are used in tilde expansion (see <a href="#tag_02_06_01">Tilde Expansion</a> ).</dd><dt><i>IFS</i></dt><dd>(Input Field Separators.) A string treated as a list of characters that is used for field splitting and to split lines intofields with the <a href="../utilities/read.html"><i>read</i></a> command. If <i>IFS</i> is not set, the shell shall behave as ifthe value of <i>IFS</i> is <space>, <tab>, and <newline>; see <a href="#tag_02_06_05">Field Splitting</a> .Implementations may ignore the value of <i>IFS</i> in the environment at the time the shell is invoked, treating <i>IFS</i> as ifit 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 ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>The value of this variable overrides the <i>LC_*</i> variables and <i>LANG ,</i> as described in the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>.</dd><dt><i>LC_COLLATE</i></dt><dd>Determine the behavior of range expressions, equivalence classes, and multi-character collating elements within patternmatching.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the interpretation of sequences of bytes of text data as characters (for example, single-byte as opposed tomulti-byte characters), which characters are defined as letters (character class <b>alpha</b>) and <blank>s (character class<b>blank</b>), and the behavior of character classes within pattern matching. Changing the value of <i>LC_CTYPE</i> after the shellhas started shall not affect the lexical processing of shell commands in the current shell execution environment or its subshells.Invoking a shell script or performing <a href="exec.html"><i>exec</i></a> <a href="../utilities/sh.html"><i>sh</i></a> subjects the newshell to the changes in <i>LC_CTYPE .</i></dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the language in which messages should be written.</dd><dt><i>LINENO</i></dt><dd>Set by the shell to a decimal number representing the current sequential line number (numbered starting with 1) within a scriptor function before it executes each command. If the user unsets or resets <i>LINENO ,</i> the variable may lose its special meaningfor the life of the shell. If the shell is not currently executing a script or function, the value of <i>LINENO</i> is unspecified.This volume of IEEE Std 1003.1-2001 specifies the effects of the variable only for systems supporting the UserPortability Utilities option.</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>A string formatted as described in the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html">Chapter 8, Environment Variables</a>, used to effect command interpretation; see <a href="#tag_02_09_01_01">Command Search and Execution</a> .</dd><dt><i>PPID</i></dt><dd>Set by the shell to the decimal process ID of the process that invoked this shell. In a subshell (see <a href="#tag_02_12">Shell Execution Environment</a> ), <i>PPID</i> shall be set to the same value as that of the parent of the currentshell. For example, <a href="../utilities/echo.html"><i>echo</i></a> $ <i>PPID</i> and ( <a href="../utilities/echo.html"><i>echo</i></a> $ <i>PPID )</i> would produce the same value. This volume ofIEEE Std 1003.1-2001 specifies the effects of the variable only for systems supporting the User Portability Utilitiesoption.</dd><dt><i>PS1</i></dt><dd>Each time an interactive shell is ready to read a command, the value of this variable shall be subjected to parameter expansionand written to standard error. The default value shall be <tt>"$ "</tt> . For users who have specific additionalimplementation-defined privileges, the default may be another, implementation-defined value. The shell shall replace each instanceof the character <tt>'!'</tt> in <i>PS1</i> with the history file number of the next command to be typed. Escaping the <tt>'!'</tt>with another <tt>'!'</tt> (that is, <tt>"!!"</tt> ) shall place the literal character <tt>'!'</tt> in the prompt. This volume ofIEEE Std 1003.1-2001 specifies the effects of the variable only for systems supporting the User Portability Utilitiesoption.</dd><dt><i>PS2</i></dt><dd>Each time the user enters a <newline> prior to completing a command line in an interactive shell, the value of thisvariable shall be subjected to parameter expansion and written to standard error. The default value is <tt>"> "</tt> . Thisvolume of IEEE Std 1003.1-2001 specifies the effects of the variable only for systems supporting the User PortabilityUtilities option.</dd><dt><i>PS4</i></dt><dd>When an execution trace ( <a href="set.html"><i>set</i></a> <b>-x</b>) is being performed in an interactive shell, before each linein the execution trace, the value of this variable shall be subjected to parameter expansion and written to standard error. Thedefault value is <tt>"+ "</tt> . This volume of IEEE Std 1003.1-2001 specifies the effects of the variable only forsystems supporting the User Portability Utilities option.</dd><dt><i>PWD</i></dt><dd>Set by the shell to be an absolute pathname of the current working directory, containing no components of type symbolic link,no components that are dot, and no components that are dot-dot when the shell is initialized. If an application sets or unsets thevalue of <i>PWD ,</i> the behaviors of the <a href="../utilities/cd.html"><i>cd</i></a> and <a href="../utilities/pwd.html"><i>pwd</i></a> utilities are unspecified.</dd></dl><h3><a name="tag_02_06"></a>Word Expansions</h3><p>This section describes the various expansions that are performed on words. Not all expansions are performed on every word, asexplained in the following sections.</p><p>Tilde expansions, parameter expansions, command substitutions, arithmetic expansions, and quote removals that occur within asingle word expand to a single field. It is only field splitting or pathname expansion that can create multiple fields from asingle word. The single exception to this rule is the expansion of the special parameter <tt>'@'</tt> within double-quotes, asdescribed in <a href="#tag_02_05_02">Special Parameters</a> .</p><p>The order of word expansion shall be as follows:</p><ol><li><p>Tilde expansion (see <a href="#tag_02_06_01">Tilde Expansion</a> ), parameter expansion (see <a href="#tag_02_06_02">ParameterExpansion</a> ), command substitution (see <a href="#tag_02_06_03">Command Substitution</a> ), and arithmetic expansion (see <ahref="#tag_02_06_04">Arithmetic Expansion</a> ) shall be performed, beginning to end. See item 5 in <a href="#tag_02_03">TokenRecognition</a> .</p></li><li><p>Field splitting (see <a href="#tag_02_06_05">Field Splitting</a> ) shall be performed on the portions of the fields generated bystep 1, unless <i>IFS</i> is null.</p></li><li><p>Pathname expansion (see <a href="#tag_02_06_06">Pathname Expansion</a> ) shall be performed, unless <a href="set.html"><i>set</i></a> <b>-f</b> is in effect.</p></li><li><p>Quote removal (see <a href="#tag_02_06_07">Quote Removal</a> ) shall always be performed last.</p></li>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -