📄 set.html
字号:
</blockquote><h4><a name="tag_04_127_07"></a>INPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>Default.</p></blockquote><h4><a name="tag_04_127_10"></a>STDOUT</h4><blockquote><p>See the DESCRIPTION.</p></blockquote><h4><a name="tag_04_127_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_127_12"></a>OUTPUT FILES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_14"></a>EXIT STATUS</h4><blockquote><p>Zero.</p></blockquote><h4><a name="tag_04_127_15"></a>CONSEQUENCES OF ERRORS</h4><blockquote><p>Default.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_04_127_16"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_17"></a>EXAMPLES</h4><blockquote><p>Write out all variables and their values:</p><pre><tt>set</tt></pre><p>Set $1, $2, and $3 and set <tt>"$#"</tt> to 3:</p><pre><tt>set c a b</tt></pre><p>Turn on the <b>-x</b> and <b>-v</b> options:</p><pre><tt>set -xv</tt></pre><p>Unset all positional parameters:</p><pre><tt>set --</tt></pre><p>Set $1 to the value of <i>x</i>, even if it begins with <tt>'-'</tt> or <tt>'+'</tt> :</p><pre><tt>set -- "$x"</tt></pre><p>Set the positional parameters to the expansion of <i>x</i>, even if <i>x</i> expands with a leading <tt>'-'</tt> or <tt>'+'</tt>:</p><pre><tt>set -- $x</tt></pre></blockquote><h4><a name="tag_04_127_18"></a>RATIONALE</h4><blockquote><p>The <i>set</i> -- form is listed specifically in the SYNOPSIS even though this usage is implied by the Utility SyntaxGuidelines. The explanation of this feature removes any ambiguity about whether the <i>set</i> -- form might be misinterpreted asbeing equivalent to <i>set</i> without any options or arguments. The functionality of this form has been adopted from theKornShell. In System V, <i>set</i> -- only unsets parameters if there is at least one argument; the only way to unset allparameters is to use <a href="../utilities/shift.html"><i>shift</i></a>. Using the KornShell version should not affect System Vscripts because there should be no reason to issue it without arguments deliberately; if it were issued as, for example:</p><pre><tt>set -- "$@"</tt></pre><p>and there were in fact no arguments resulting from <tt>"$@"</tt>, unsetting the parameters would have no result.</p><p>The <i>set</i> + form in early proposals was omitted as being an unnecessary duplication of <i>set</i> alone and not widespreadhistorical practice.</p><p>The <i>noclobber</i> option was changed to allow <i>set</i> <b>-C</b> as well as the <i>set</i> <b>-o</b> <i>noclobber</i>option. The single-letter version was added so that the historical <tt>"$-"</tt> paradigm would not be broken; see <a href="xcu_chap02.html#tag_02_05_02"><i>Special Parameters</i></a>.</p><p>The <b>-h</b> flag is related to command name hashing and is only required on XSI-conformant systems.</p><p>The following <i>set</i> flags were omitted intentionally with the following rationale:</p><dl compact><dt><b>-k</b></dt><dd>The <b>-k</b> flag was originally added by the author of the Bourne shell to make it easier for users of pre-release versionsof the shell. In early versions of the Bourne shell the construct <i>set</i> <i>name</i>= <i>value</i> had to be used to assignvalues to shell variables. The problem with <b>-k</b> is that the behavior affects parsing, virtually precluding writing anycompilers. To explain the behavior of <b>-k</b>, it is necessary to describe the parsing algorithm, which isimplementation-defined. For example: <pre><tt>set -k; echo</tt> <i>name</i><tt>=</tt><i>value</i></pre><p>and:</p><pre><tt>set -kecho</tt> <i>name</i><tt>=</tt><i>value</i></pre><p>behave differently. The interaction with functions is even more complex. What is more, the <b>-k</b> flag is never needed, sincethe command line could have been reordered.</p></dd><dt><b>-t</b></dt><dd>The <b>-t</b> flag is hard to specify and almost never used. The only known use could be done with here-documents. Moreover,the behavior with <i>ksh</i> and <a href="../utilities/sh.html"><i>sh</i></a> differs. Thereference page says that it exits after reading and executing one command. What is one command? If the input is <i>date</i>;<i>date</i>, <a href="../utilities/sh.html"><i>sh</i></a> executes both <a href="../utilities/date.html"><i>date</i></a> commandswhile <i>ksh</i> does only the first.</dd></dl><p>Consideration was given to rewriting <i>set</i> to simplify its confusing syntax. A specific suggestion was that the <a href="../utilities/unset.html"><i>unset</i></a> utility should be used to unset options instead of using the non- <a href="../functions/getopt.html"><i>getopt</i>()</a> -able + <i>option</i> syntax. However, the conclusion was reached that thehistorical practice of using + <i>option</i> was satisfactory and that there was no compelling reason to modify such widespreadhistorical practice.</p><p>The <b>-o</b> option was adopted from the KornShell to address user needs. In addition to its generally friendly interface,<b>-o</b> is needed to provide the <a href="../utilities/vi.html"><i>vi</i></a> command line editing mode, for which historicalpractice yields no single-letter option name. (Although it might have been possible to invent such a letter, it was recognized thatother editing modes would be developed and <b>-o</b> provides ample name space for describing such extensions.)</p><p>Historical implementations are inconsistent in the format used for <b>-o</b> option status reporting. The <b>+o</b> formatwithout an option-argument was added to allow portable access to the options that can be saved and then later restored using, forinstance, a dot script.</p><p>Historically, <a href="../utilities/sh.html"><i>sh</i></a> did trace the command <i>set</i> <b>+x</b>, but <i>ksh</i> did not.</p><p>The <i>ignoreeof</i> setting prevents accidental logouts when the end-of-file character (typically <control>-D) isentered. A user shall explicitly <a href="../utilities/exit.html"><i>exit</i></a> to leave the interactive shell.</p><p>The <i>set</i> <b>-m</b> option was added to apply only to the UPE because it applies primarily to interactive use, not shellscript applications.</p><p>The ability to do asynchronous notification became available in the 1988 version of the KornShell. To have it occur, the userhad to issue the command:</p><pre><tt>trap "jobs -n" CLD</tt></pre><p>The C shell provides two different levels of an asynchronous notification capability. The environment variable <i>notify</i> isanalogous to what is done in <i>set</i> <b>-b</b> or <i>set</i> <b>-o</b> <i>notify</i>. When set, it notifies the user immediatelyof background job completions. When unset, this capability is turned off.</p><p>The other notification ability comes through the built-in utility <i>notify</i>. Thesyntax is:</p><pre><tt>notify</tt> <b>[</b><tt>%job ...</tt> <b>]</b></pre><p>By issuing <i>notify</i> with no operands, it causes the C shell to notify the userasynchronously when the state of the current job changes. If given operands, <i>notify</i>asynchronously informs the user of changes in the states of the specified jobs.</p><p>To add asynchronous notification to the POSIX shell, neither the KornShell extensions to <a href="../utilities/trap.html"><i>trap</i></a>, nor the C shell <i>notify</i> environment variableseemed appropriate ( <i>notify</i> is not a proper POSIX environment variable name).</p><p>The <i>set</i> <b>-b</b> option was selected as a compromise.</p><p>The <i>notify</i> built-in was considered to have more functionality than was requiredfor simple asynchronous notification.</p></blockquote><h4><a name="tag_04_127_19"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_04_127_20"></a>SEE ALSO</h4><blockquote><p><a href="xcu_chap02.html#tag_02_14"><i>Special Built-In Utilities</i></a></p></blockquote><h4><a name="tag_04_127_21"></a>CHANGE HISTORY</h4><h4><a name="tag_04_127_22"></a>Issue 6</h4><blockquote><p>The obsolescent <i>set</i> command name followed by <tt>'-'</tt> has been removed.</p><p>The following new requirements on POSIX implementations derive from alignment with the Single UNIX Specification:</p><ul><li><p>The <i>nolog</i> option is added to <i>set</i> <b>-o</b>.</p></li></ul><p>IEEE PASC Interpretation 1003.2 #167 is applied, clarifying that the options default also takes into account the description ofthe option.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/5 is applied so that the reference page sections use terms asdescribed in the Utility Description Defaults ( <a href="xcu_chap01.html#tag_01_11"><i>Utility Description Defaults</i></a>). Nochange in behavior is intended.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XCU/TC1/D6/8 is applied, changing the square brackets in the example inRATIONALE to be in bold, which is the typeface used for optional items.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -