This builtin is so complicated that it deserves its own section. set
allows you to change the values of shell options and set the positional
parameters, or to display the names and values of shell variables.
set ¶set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [argument ...] set [+abefhkmnptuvxBCEHPT] [+o option-name] [--] [-] [argument ...] set -o set +o
If no options or arguments are supplied, set 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 POSIX mode, only shell variables are listed.
When options are supplied, they set or unset shell attributes. Any arguments remaining after option processing replace the positional parameters.
Options, if specified, have the following meanings:
-aEach variable or function that is created or modified is given the export attribute and marked for export to the environment of subsequent commands.
-bCause the status of terminated background jobs to be reported immediately, rather than before printing the next primary prompt or, under some circumstances, when a foreground command exits. This is effective only when job control is enabled.
-eExit immediately if
a pipeline (see Pipelines), which may consist of a single simple command
(see Simple Commands),
a list (see Lists of Commands),
or a compound command (see Compound Commands)
returns a non-zero status.
The shell does not exit if the command that fails is part of the
command list immediately following a
while or until reserved word,
part of the test in an if statement,
part of any command executed in a && or || list except
the command following the final && or ||,
any command in a pipeline but the last
(subject to the state of the pipefail shell option),
or if the command’s return status is being inverted with !.
If a compound command other than a subshell
returns a non-zero status because a command failed
while -e was being ignored, the shell does not exit.
A trap on ERR, if set, is executed before the shell exits.
This option applies to the shell environment and each subshell environment separately (see Command Execution Environment), and may cause subshells to exit before executing all the commands in the subshell.
If a compound command or shell function executes in a context where -e is being ignored, none of the commands executed within the compound command or function body will be affected by the -e setting, even if -e is set and a command returns a failure status. If a compound command or shell function sets -e while executing in a context where -e is ignored, that setting will not have any effect until the compound command or the command containing the function call completes.
-fDisable filename expansion (globbing).
-hLocate and remember (hash) commands as they are looked up for execution. This option is enabled by default.
-kAll arguments in the form of assignment statements are placed in the environment for a command, not just those that precede the command name.
-mJob control is enabled (see Job Control). All processes run in a separate process group. When a background job completes, the shell prints a line containing its exit status.
-nRead commands but do not execute them. This may be used to check a script for syntax errors. This option is ignored by interactive shells.
-o option-nameSet the option corresponding to option-name.
If -o is supplied with no option-name,
set prints the current shell options settings.
If +o is supplied with no option-name,
set prints a series of
set
commands to recreate the current option settings
on the standard output.
Valid option names are:
allexportSame as -a.
braceexpandSame as -B.
emacsUse an emacs-style line editing interface (see Command Line Editing).
This also affects the editing interface used for read -e.
errexitSame as -e.
errtraceSame as -E.
functraceSame as -T.
hashallSame as -h.
histexpandSame as -H.
historyEnable command history, as described in Bash History Facilities. This option is on by default in interactive shells.
ignoreeofAn interactive shell will not exit upon reading EOF.
keywordSame as -k.
monitorSame as -m.
noclobberSame as -C.
noexecSame as -n.
noglobSame as -f.
nologCurrently ignored.
notifySame as -b.
nounsetSame as -u.
onecmdSame as -t.
physicalSame as -P.
pipefailIf 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.
posixEnable POSIX mode; change the behavior of Bash where the default operation differs from the POSIX standard to match the standard (see Bash and POSIX). This is intended to make Bash behave as a strict superset of that standard.
privilegedSame as -p.
verboseSame as -v.
viUse a vi-style line editing interface.
This also affects the editing interface used for read -e.
xtraceSame as -x.
-pTurn on privileged mode.
In this mode, the $BASH_ENV and $ENV files are not
processed, shell functions are not inherited from the environment,
and the SHELLOPTS, BASHOPTS, CDPATH and GLOBIGNORE
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 -p option is not supplied, these actions
are taken and the effective user id is set to the real user id.
If the -p 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.
-rEnable restricted shell mode (see The Restricted Shell). This option cannot be unset once it has been set.
-tExit after reading and executing one command.
-uTreat unset variables and parameters other than the special parameters ‘@’ or ‘*’, or array variables subscripted with ‘@’ or ‘*’, as an error when performing parameter expansion. An error message will be written to the standard error, and a non-interactive shell will exit.
-vPrint shell input lines to standard error as they are read.
-xPrint a trace of simple commands, for commands, case
commands, select commands, and arithmetic for commands
and their arguments or associated word lists to the standard error
after they are expanded and before they are executed.
The shell prints the expanded value of the PS4 variable before
the command and its expanded arguments.
-BThe shell will perform brace expansion (see Brace Expansion). This option is on by default.
-CPrevent output redirection using ‘>’, ‘>&’, and ‘<>’ from overwriting existing files. Using the redirection operator ‘>|’ instead of ‘>’ will override this and force the creation of an output file.
-EIf set, any trap on ERR is inherited by shell functions, command
substitutions, and commands executed in a subshell environment.
The ERR trap is normally not inherited in such cases.
-HEnable ‘!’ style history substitution (see History Expansion). This option is on by default for interactive shells.
-PIf set, Bash does not resolve symbolic links when executing commands
such as cd which change the current directory.
It uses the physical directory structure instead.
By default, Bash follows
the logical chain of directories when performing commands
which change the current directory.
For example, if /usr/sys is a symbolic link to /usr/local/sys then:
$ cd /usr/sys; echo $PWD /usr/sys $ cd ..; pwd /usr
If set -P is on, then:
$ cd /usr/sys; echo $PWD /usr/local/sys $ cd ..; pwd /usr/local
-TIf set, any traps on DEBUG and RETURN are inherited by
shell functions, command substitutions, and commands executed
in a subshell environment.
The DEBUG and RETURN traps are normally not inherited
in such cases.
--If no arguments follow this option, unset the positional parameters. Otherwise, the positional parameters are set to the arguments, even if some of them begin with a ‘-’.
-Signal the end of options, and assign all remaining arguments to the positional parameters. The -x and -v options are turned off. If there are no arguments, the positional parameters remain unchanged.
Using ‘+’ rather than ‘-’ 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 $-.
The remaining N arguments are positional parameters and are
assigned, in order, to $1, $2, … $N.
The special parameter # is set to N.
The return status is always zero unless an invalid option is supplied.