This builtin is so complicated that it deserves its own section.
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 [--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:
untilkeyword, part of the test in an
ifstatement, part of any command executed in a
||list except the command following the final
||, 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.
emacs-style line editing interface (see Command Line Editing). This also affects the editing interface used for
vi-style line editing interface. This also affects the editing interface used for
-poption is not supplied, these actions are taken and the effective user id is set to the real user id. If the
-poption 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.
selectcommands, and arithmetic
forcommands 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.
ERRis inherited by shell functions, command substitutions, and commands executed in a subshell environment. The
ERRtrap is normally not inherited in such cases.
cdwhich 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
set -P is on, then:
$ cd /usr/sys; echo $PWD /usr/local/sys $ cd ..; pwd /usr/local
RETURNare inherited by shell functions, command substitutions, and commands executed in a subshell environment. The
RETURNtraps 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
The special parameter
# is set to N.
The return status is always zero unless an invalid option is supplied.