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] [argument ...] set [+abefhkmnptuvxBCEHPT] [+o option] [argument ...]
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. Options, if specified, have the following meanings:
-a
-b
-e
while
or until
keyword,
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,
or if the command's return status is being inverted with !
.
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.
-f
-h
-k
-m
-n
-o
option-nameallexport
-a
.
braceexpand
-B
.
emacs
emacs
-style line editing interface (see Command Line Editing).
This also affects the editing interface used for read -e
.
errexit
-e
.
errtrace
-E
.
functrace
-T
.
hashall
-h
.
histexpand
-H
.
history
ignoreeof
keyword
-k
.
monitor
-m
.
noclobber
-C
.
noexec
-n
.
noglob
-f
.
nolog
notify
-b
.
nounset
-u
.
onecmd
-t
.
physical
-P
.
pipefail
posix
privileged
-p
.
verbose
-v
.
vi
vi
-style line editing interface.
This also affects the editing interface used for read -e
.
xtrace
-x
.
-p
-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.
-t
-u
-v
-x
for
commands, case
commands, select
commands, and arithmetic for
commands
and their arguments or associated word lists after they are
expanded and before they are executed. The value of the PS4
variable is expanded and the resultant value is printed before
the command and its expanded arguments.
-B
-C
-E
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.
-H
-P
cd
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.
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
-T
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.
--
-
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.