📄 set.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-2004 IEEE and The Open Group, All Rights Reserved --><title>set</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="set"></a> <a name="tag_04_127"></a><!-- set --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_127_01"></a>NAME</h4><blockquote>set - set or unset options and positional parameters</blockquote><h4><a name="tag_04_127_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> set</tt> <b>[</b><tt>-abCefmnuvx</tt><b>]<img src="../images/opt-start.gif" border="0">[</b><tt>-h</tt><b>]<img src="../images/opt-end.gif" border="0">[</b><tt>-o</tt><i>option</i><b>][</b><i>argument</i><tt>...</tt><b>]</b><tt><br><br><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> set</tt> <b>[</b><tt>+abCefmnuvx</tt><b>]<img src="../images/opt-start.gif" border="0">[</b><tt>+h</tt><b>]<img src="../images/opt-end.gif" border="0">[</b><tt>+o</tt><i>option</i><b>][</b><i>argument</i><b>...]</b><tt><br><br>set --</tt> <b>[</b><i>argument</i><tt>...</tt><b>]</b><tt><br><br>set -o<br><br> set +o<br></tt></code></p></blockquote><h4><a name="tag_04_127_03"></a>DESCRIPTION</h4><blockquote><p>If no <i>option</i>s or <i>argument</i>s are specified, <i>set</i> shall write the names and values of all shell variables inthe collation sequence of the current locale. Each <i>name</i> shall start on a separate line, using the format:</p><pre><tt>"%s=%s\n", <</tt><i>name</i><tt>>, <</tt><i>value</i><tt>></tt></pre><p>The <i>value</i> string shall be written with appropriate quoting; see the description of shell quoting in <a href="xcu_chap02.html#tag_02_02"><i>Quoting</i></a>. The output shall be suitable for reinput to the shell, setting or resetting, asfar as possible, the variables that are currently set; read-only variables cannot be reset.</p><p>When options are specified, they shall set or unset attributes of the shell, as described below. When <i>argument</i>s arespecified, they cause positional parameters to be set or unset, as described below. Setting or unsetting attributes and positionalparameters are not necessarily related actions, but they can be combined in a single invocation of <i>set</i>.</p><p>The <i>set</i> special built-in shall support 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> except that options can be specified witheither a leading hyphen (meaning enable the option) or plus sign (meaning disable it) unless otherwise specified.</p><p>Implementations shall support the options in the following list in both their hyphen and plus-sign forms. These options can alsobe specified as options to <a href="../utilities/sh.html"><i>sh</i></a>.</p><dl compact><dt><b>-a</b></dt><dd>When this option is on, the <i>export</i> attribute shall be set for each variable to which an assignment is performed; see theBase Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap04.html#tag_04_21">Section 4.21, VariableAssignment</a>. If the assignment precedes a utility name in a command, the <i>export</i> attribute shall not persist in thecurrent execution environment after the utility completes, with the exception that preceding one of the special built-in utilitiescauses the <i>export</i> attribute to persist after the built-in has completed. If the assignment does not precede a utility namein the command, or if the assignment is a result of the operation of the <a href="../utilities/getopts.html"><i>getopts</i></a> or<a href="../utilities/read.html"><i>read</i></a> utilities, the <i>export</i> attribute shall persist until the variable isunset.</dd><dt><b>-b</b></dt><dd>This option shall be supported if the implementation supports the User Portability Utilities option. It shall cause the shellto notify the user asynchronously of background job completions. The following message is written to standard error: <pre><tt>"[%d]%c %s%s\n", <</tt><i>job-number</i><tt>>, <</tt><i>current</i><tt>>, <status>, <job-name></tt></pre><p>where the fields shall be as follows:</p><dl compact><dt><<i>current</i>></dt><dd>The character <tt>'+'</tt> identifies the job that would be used as a default for the <a href="../utilities/fg.html"><i>fg</i></a> or <a href="../utilities/bg.html"><i>bg</i></a> utilities; this job can also be specifiedusing the <i>job_id</i> <tt>"%+"</tt> or <tt>"%%"</tt>. The character <tt>'-'</tt> identifies the job that would become thedefault if the current default job were to exit; this job can also be specified using the <i>job_id</i> <tt>"%-"</tt>. For otherjobs, this field is a <space>. At most one job can be identified with <tt>'+'</tt> and at most one job can be identified with<tt>'-'</tt>. If there is any suspended job, then the current job shall be a suspended job. If there are at least two suspendedjobs, then the previous job also shall be a suspended job.</dd><dt><<i>job-number</i>></dt><dd>A number that can be used to identify the process group to the <a href="../utilities/wait.html"><i>wait</i></a>, <a href="../utilities/fg.html"><i>fg</i></a>, <a href="../utilities/bg.html"><i>bg</i></a>, and <a href="../utilities/kill.html"><i>kill</i></a> utilities. Using these utilities, the job can be identified by prefixing the job numberwith <tt>'%'</tt>.</dd><dt><<i>status</i>></dt><dd>Unspecified.</dd><dt><<i>job-name</i>></dt><dd>Unspecified.</dd></dl><p>When the shell notifies the user a job has been completed, it may remove the job's process ID from the list of those known inthe current shell execution environment; see <a href="xcu_chap02.html#tag_02_09_03_02"><i>Asynchronous Lists</i></a>. Asynchronousnotification shall not be enabled by default.</p></dd><dt><b>-C</b></dt><dd>(Uppercase C.) Prevent existing files from being overwritten by the shell's <tt>'>'</tt> redirection operator (see <a href="xcu_chap02.html#tag_02_07_02"><i>Redirecting Output</i></a>); the <tt>">|"</tt> redirection operator shall override this<i>noclobber</i> option for an individual file.</dd><dt><b>-e</b></dt><dd>When this option is on, if a simple command fails for any of the reasons listed in <a href="xcu_chap02.html#tag_02_08_01"><i>Consequences of Shell Errors</i></a> or returns an exit status value >0, and is not part ofthe compound list following a <b>while</b>, <b>until</b>, or <b>if</b> keyword, and is not a part of an AND or OR list, and is nota pipeline preceded by the <b>!</b> reserved word, then the shell shall immediately exit.</dd><dt><b>-f</b></dt><dd>The shell shall disable pathname expansion.</dd><dt><b>-h</b></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Locate and remember utilities invoked by functions as those functions are defined (the utilities are normally located when thefunction is executed). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt><b>-m</b></dt><dd>This option shall be supported if the implementation supports the User Portability Utilities option. All jobs shall be run intheir own process groups. Immediately before the shell issues a prompt after completion of the background job, a message reportingthe exit status of the background job shall be written to standard error. If a foreground job stops, the shell shall write amessage to standard error to that effect, formatted as described by the <a href="../utilities/jobs.html"><i>jobs</i></a> utility.In addition, if a job changes status other than exiting (for example, if it stops for input or output or is stopped by a SIGSTOPsignal), the shell shall write a similar message immediately prior to writing the next prompt. This option is enabled by defaultfor interactive shells.</dd><dt><b>-n</b></dt><dd>The shell shall read commands but does not execute them; this can be used to check for shell script syntax errors. Aninteractive shell may ignore this option.</dd><dt><b>-o</b></dt><dd>Write the current settings of the options to standard output in an unspecified format.</dd><dt><b>+o</b></dt><dd>Write the current option settings to standard output in a format that is suitable for reinput to the shell as commands thatachieve the same options settings.</dd><dt><b>-o </b> <i>option</i></dt><dd>This option is supported if the system supports the User Portability Utilities option. It shall set various options, many of whichshall be equivalent to the single option letters. The following values of <i>option</i> shall be supported: <dl compact><dt><i>allexport</i></dt><dd>Equivalent to <b>-a</b>.</dd><dt><i>errexit</i></dt><dd>Equivalent to <b>-e</b>.</dd><dt><i>ignoreeof</i></dt><dd>Prevent an interactive shell from exiting on end-of-file. This setting prevents accidental logouts when <control>-D isentered. A user shall explicitly <a href="../utilities/exit.html"><i>exit</i></a> to leave the interactive shell.</dd><dt><i>monitor</i></dt><dd>Equivalent to <b>-m</b>. This option is supported if the system supports the User Portability Utilities option.</dd><dt><i>noclobber</i></dt><dd>Equivalent to <b>-C</b> (uppercase C).</dd><dt><i>noglob</i></dt><dd>Equivalent to <b>-f</b>.</dd><dt><i>noexec</i></dt><dd>Equivalent to <b>-n</b>.</dd><dt><i>nolog</i></dt><dd>Prevent the entry of function definitions into the command history; see <a href="../utilities/sh.html#tag_04_128_13_01"><i>Command History List</i></a>.</dd><dt><i>notify</i></dt><dd>Equivalent to <b>-b</b>.</dd><dt><i>nounset</i></dt><dd>Equivalent to <b>-u</b>.</dd><dt><i>verbose</i></dt><dd>Equivalent to <b>-v</b>.</dd><dt><i>vi</i></dt><dd>Allow shell command line editing using the built-in <a href="../utilities/vi.html"><i>vi</i></a> editor. Enabling <a href="../utilities/vi.html"><i>vi</i></a> mode shall disable any other command line editing mode provided as an implementationextension. <p>It need not be possible to set <a href="../utilities/vi.html"><i>vi</i></a> mode on for certain block-mode terminals.</p></dd><dt><i>xtrace</i></dt><dd>Equivalent to <b>-x</b>.</dd></dl></dd><dt><b>-u</b></dt><dd>The shell shall write a message to standard error when it tries to expand a variable that is not set and immediately exit. Aninteractive shell shall not exit.</dd><dt><b>-v</b></dt><dd>The shell shall write its input to standard error as it is read.</dd><dt><b>-x</b></dt><dd>The shell shall write to standard error a trace for each command after it expands the command and before it executes it. It isunspecified whether the command that turns tracing off is traced.</dd></dl><p>The default for all these options shall be off (unset) unless stated otherwise in the description of the option or unless theshell was invoked with them on; see <a href="../utilities/sh.html"><i>sh</i></a>.</p><p>The remaining arguments shall be assigned in order to the positional parameters. The special parameter <tt>'#'</tt> shall be setto reflect the number of positional parameters. All positional parameters shall be unset before any new values are assigned.</p><p>The special argument <tt>"--"</tt> immediately following the <i>set</i> command name can be used to delimit the arguments if thefirst argument begins with <tt>'+'</tt> or <tt>'-'</tt>, or to prevent inadvertent listing of all shell variables when there areno arguments. The command <i>set</i> <b>--</b> without <i>argument</i> shall unset all positional parameters and set the specialparameter <tt>'#'</tt> to zero.</p></blockquote><h4><a name="tag_04_127_04"></a>OPTIONS</h4><blockquote><p>See the DESCRIPTION.</p></blockquote><h4><a name="tag_04_127_05"></a>OPERANDS</h4><blockquote><p>See the DESCRIPTION.</p></blockquote><h4><a name="tag_04_127_06"></a>STDIN</h4><blockquote><p>Not used.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -