1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
<h1 class="subsection">The Set Builtin</h1> <p>This builtin is so complicated that it deserves its own section. <code>set</code> allows you to change the values of shell options and set the positional parameters, or to display the names and values of shell variables. </p> <dl compact> <dt id="index-set"><span><code>set</code></span></dt> <dd>
<div class="example"> <pre class="example">set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [argument …]
set [+abefhkmnptuvxBCEHPT] [+o option-name] [--] [-] [argument …]
</pre>
</div> <p>If no options or arguments are supplied, <code>set</code> displays the names and values of all shell variables and functions, sorted according to the current locale, in a format that may be reused as input for setting or resetting the currently-set variables. Read-only variables cannot be reset. In <small>POSIX</small> mode, only shell variables are listed. </p> <p>When options are supplied, they set or unset shell attributes. Options, if specified, have the following meanings: </p> <dl compact> <dt><span><code>-a</code></span></dt> <dd>
<p>Each variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands. </p> </dd> <dt><span><code>-b</code></span></dt> <dd>
<p>Cause the status of terminated background jobs to be reported immediately, rather than before printing the next primary prompt. </p> </dd> <dt><span><code>-e</code></span></dt> <dd>
<p>Exit immediately if a pipeline (see <a href="pipelines">Pipelines</a>), which may consist of a single simple command (see <a href="simple-commands">Simple Commands</a>), a list (see <a href="lists">Lists of Commands</a>), or a compound command (see <a href="compound-commands">Compound Commands</a>) returns a non-zero status. The shell does not exit if the command that fails is part of the command list immediately following a <code>while</code> or <code>until</code> keyword, part of the test in an <code>if</code> statement, part of any command executed in a <code>&&</code> or <code>||</code> list except the command following the final <code>&&</code> or <code>||</code>, any command in a pipeline but the last, or if the command’s return status is being inverted with <code>!</code>. If a compound command other than a subshell returns a non-zero status because a command failed while <samp>-e</samp> was being ignored, the shell does not exit. A trap on <code>ERR</code>, if set, is executed before the shell exits. </p> <p>This option applies to the shell environment and each subshell environment separately (see <a href="command-execution-environment">Command Execution Environment</a>), and may cause subshells to exit before executing all the commands in the subshell. </p> <p>If a compound command or shell function executes in a context where <samp>-e</samp> is being ignored, none of the commands executed within the compound command or function body will be affected by the <samp>-e</samp> setting, even if <samp>-e</samp> is set and a command returns a failure status. If a compound command or shell function sets <samp>-e</samp> while executing in a context where <samp>-e</samp> is ignored, that setting will not have any effect until the compound command or the command containing the function call completes. </p> </dd> <dt><span><code>-f</code></span></dt> <dd>
<p>Disable filename expansion (globbing). </p> </dd> <dt><span><code>-h</code></span></dt> <dd>
<p>Locate and remember (hash) commands as they are looked up for execution. This option is enabled by default. </p> </dd> <dt><span><code>-k</code></span></dt> <dd>
<p>All arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name. </p> </dd> <dt><span><code>-m</code></span></dt> <dd>
<p>Job control is enabled (see <a href="job-control">Job Control</a>). All processes run in a separate process group. When a background job completes, the shell prints a line containing its exit status. </p> </dd> <dt><span><code>-n</code></span></dt> <dd>
<p>Read commands but do not execute them. This may be used to check a script for syntax errors. This option is ignored by interactive shells. </p> </dd> <dt><span><code>-o <var>option-name</var></code></span></dt> <dd> <p>Set the option corresponding to <var>option-name</var>: </p> <dl compact> <dt><span><code>allexport</code></span></dt> <dd>
<p>Same as <code>-a</code>. </p> </dd> <dt><span><code>braceexpand</code></span></dt> <dd>
<p>Same as <code>-B</code>. </p> </dd> <dt><span><code>emacs</code></span></dt> <dd>
<p>Use an <code>emacs</code>-style line editing interface (see <a href="command-line-editing">Command Line Editing</a>). This also affects the editing interface used for <code>read -e</code>. </p> </dd> <dt><span><code>errexit</code></span></dt> <dd>
<p>Same as <code>-e</code>. </p> </dd> <dt><span><code>errtrace</code></span></dt> <dd>
<p>Same as <code>-E</code>. </p> </dd> <dt><span><code>functrace</code></span></dt> <dd>
<p>Same as <code>-T</code>. </p> </dd> <dt><span><code>hashall</code></span></dt> <dd>
<p>Same as <code>-h</code>. </p> </dd> <dt><span><code>histexpand</code></span></dt> <dd>
<p>Same as <code>-H</code>. </p> </dd> <dt><span><code>history</code></span></dt> <dd>
<p>Enable command history, as described in <a href="bash-history-facilities">Bash History Facilities</a>. This option is on by default in interactive shells. </p> </dd> <dt><span><code>ignoreeof</code></span></dt> <dd>
<p>An interactive shell will not exit upon reading EOF. </p> </dd> <dt><span><code>keyword</code></span></dt> <dd>
<p>Same as <code>-k</code>. </p> </dd> <dt><span><code>monitor</code></span></dt> <dd>
<p>Same as <code>-m</code>. </p> </dd> <dt><span><code>noclobber</code></span></dt> <dd>
<p>Same as <code>-C</code>. </p> </dd> <dt><span><code>noexec</code></span></dt> <dd>
<p>Same as <code>-n</code>. </p> </dd> <dt><span><code>noglob</code></span></dt> <dd>
<p>Same as <code>-f</code>. </p> </dd> <dt><span><code>nolog</code></span></dt> <dd>
<p>Currently ignored. </p> </dd> <dt><span><code>notify</code></span></dt> <dd>
<p>Same as <code>-b</code>. </p> </dd> <dt><span><code>nounset</code></span></dt> <dd>
<p>Same as <code>-u</code>. </p> </dd> <dt><span><code>onecmd</code></span></dt> <dd>
<p>Same as <code>-t</code>. </p> </dd> <dt><span><code>physical</code></span></dt> <dd>
<p>Same as <code>-P</code>. </p> </dd> <dt><span><code>pipefail</code></span></dt> <dd>
<p>If set, the return value of a pipeline is the value of the last (rightmost) command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default. </p> </dd> <dt><span><code>posix</code></span></dt> <dd>
<p>Change the behavior of Bash where the default operation differs from the <small>POSIX</small> standard to match the standard (see <a href="bash-posix-mode">Bash POSIX Mode</a>). This is intended to make Bash behave as a strict superset of that standard. </p> </dd> <dt><span><code>privileged</code></span></dt> <dd>
<p>Same as <code>-p</code>. </p> </dd> <dt><span><code>verbose</code></span></dt> <dd>
<p>Same as <code>-v</code>. </p> </dd> <dt><span><code>vi</code></span></dt> <dd>
<p>Use a <code>vi</code>-style line editing interface. This also affects the editing interface used for <code>read -e</code>. </p> </dd> <dt><span><code>xtrace</code></span></dt> <dd><p>Same as <code>-x</code>. </p></dd> </dl> </dd> <dt><span><code>-p</code></span></dt> <dd>
<p>Turn on privileged mode. In this mode, the <code>$BASH_ENV</code> and <code>$ENV</code> files are not processed, shell functions are not inherited from the environment, and the <code>SHELLOPTS</code>, <code>BASHOPTS</code>, <code>CDPATH</code> and <code>GLOBIGNORE</code> variables, if they appear in the environment, are ignored. If the shell is started with the effective user (group) id not equal to the real user (group) id, and the <samp>-p</samp> option is not supplied, these actions are taken and the effective user id is set to the real user id. If the <samp>-p</samp> option is supplied at startup, the effective user id is not reset. Turning this option off causes the effective user and group ids to be set to the real user and group ids. </p> </dd> <dt><span><code>-r</code></span></dt> <dd>
<p>Enable restricted shell mode. This option cannot be unset once it has been set. </p> </dd> <dt><span><code>-t</code></span></dt> <dd>
<p>Exit after reading and executing one command. </p> </dd> <dt><span><code>-u</code></span></dt> <dd>
<p>Treat unset variables and parameters other than the special parameters ‘<samp>@</samp>’ or ‘<samp>*</samp>’, or array variables subscripted with ‘<samp>@</samp>’ or ‘<samp>*</samp>’, as an error when performing parameter expansion. An error message will be written to the standard error, and a non-interactive shell will exit. </p> </dd> <dt><span><code>-v</code></span></dt> <dd>
<p>Print shell input lines as they are read. </p> </dd> <dt><span><code>-x</code></span></dt> <dd>
<p>Print a trace of simple commands, <code>for</code> commands, <code>case</code> commands, <code>select</code> commands, and arithmetic <code>for</code> commands and their arguments or associated word lists after they are expanded and before they are executed. The value of the <code>PS4</code> variable is expanded and the resultant value is printed before the command and its expanded arguments. </p> </dd> <dt><span><code>-B</code></span></dt> <dd>
<p>The shell will perform brace expansion (see <a href="brace-expansion">Brace Expansion</a>). This option is on by default. </p> </dd> <dt><span><code>-C</code></span></dt> <dd>
<p>Prevent output redirection using ‘<samp>></samp>’, ‘<samp>>&</samp>’, and ‘<samp><></samp>’ from overwriting existing files. </p> </dd> <dt><span><code>-E</code></span></dt> <dd>
<p>If set, any trap on <code>ERR</code> is inherited by shell functions, command substitutions, and commands executed in a subshell environment. The <code>ERR</code> trap is normally not inherited in such cases. </p> </dd> <dt><span><code>-H</code></span></dt> <dd>
<p>Enable ‘<samp>!</samp>’ style history substitution (see <a href="history-interaction">History Expansion</a>). This option is on by default for interactive shells. </p> </dd> <dt><span><code>-P</code></span></dt> <dd>
<p>If set, do not resolve symbolic links when performing commands such as <code>cd</code> which change the current directory. The physical directory is used instead. By default, Bash follows the logical chain of directories when performing commands which change the current directory. </p> <p>For example, if <samp>/usr/sys</samp> is a symbolic link to <samp>/usr/local/sys</samp> then: </p>
<div class="example"> <pre class="example">$ cd /usr/sys; echo $PWD
/usr/sys
$ cd ..; pwd
/usr
</pre>
</div> <p>If <code>set -P</code> is on, then: </p>
<div class="example"> <pre class="example">$ cd /usr/sys; echo $PWD
/usr/local/sys
$ cd ..; pwd
/usr/local
</pre>
</div> </dd> <dt><span><code>-T</code></span></dt> <dd>
<p>If set, any trap on <code>DEBUG</code> and <code>RETURN</code> are inherited by shell functions, command substitutions, and commands executed in a subshell environment. The <code>DEBUG</code> and <code>RETURN</code> traps are normally not inherited in such cases. </p> </dd> <dt><span><code>--</code></span></dt> <dd>
<p>If no arguments follow this option, then the positional parameters are unset. Otherwise, the positional parameters are set to the <var>arguments</var>, even if some of them begin with a ‘<samp>-</samp>’. </p> </dd> <dt><span><code>-</code></span></dt> <dd><p>Signal the end of options, cause all remaining <var>arguments</var> to be assigned to the positional parameters. The <samp>-x</samp> and <samp>-v</samp> options are turned off. If there are no arguments, the positional parameters remain unchanged. </p></dd> </dl> <p>Using ‘<samp>+</samp>’ rather than ‘<samp>-</samp>’ causes these options to be turned off. The options can also be used upon invocation of the shell. The current set of options may be found in <code>$-</code>. </p> <p>The remaining N <var>arguments</var> are positional parameters and are assigned, in order, to <code>$1</code>, <code>$2</code>, … <code>$N</code>. The special parameter <code>#</code> is set to N. </p> <p>The return status is always zero unless an invalid option is supplied. </p>
</dd> </dl><div class="_attribution">
<p class="_attribution-p">
Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br>
<a href="https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html</a>
</p>
</div>
|