bash: The Set Builtin
1
1 4.3.1 The Set Builtin
1 ---------------------
1
1 This builtin is so complicated that it deserves its own section. 'set'
1 allows you to change the values of shell options and set the positional
1 parameters, or to display the names and values of shell variables.
1
1 'set'
1 set [--abefhkmnptuvxBCEHPT] [-o OPTION-NAME] [ARGUMENT ...]
1 set [+abefhkmnptuvxBCEHPT] [+o OPTION-NAME] [ARGUMENT ...]
1
1 If no options or arguments are supplied, 'set' displays the names
1 and values of all shell variables and functions, sorted according
1 to the current locale, in a format that may be reused as input for
1 setting or resetting the currently-set variables. Read-only
1 variables cannot be reset. In POSIX mode, only shell variables are
1 listed.
1
1 When options are supplied, they set or unset shell attributes.
1 Options, if specified, have the following meanings:
1
1 '-a'
1 Each variable or function that is created or modified is given
1 the export attribute and marked for export to the environment
1 of subsequent commands.
1
1 '-b'
1 Cause the status of terminated background jobs to be reported
1 immediately, rather than before printing the next primary
1 prompt.
1
1 '-e'
1 Exit immediately if a pipeline (⇒Pipelines), which may
1 consist of a single simple command (⇒Simple Commands),
DONTPRINTYET 1 a list (⇒Lists), or a compound command (*noteCompound
1DONTPRINTYET 1 a list (⇒Lists), or a compound command (⇒Compound
Commands) returns a non-zero status. The shell does not
1 exit if the command that fails is part of the command list
1 immediately following a 'while' or 'until' keyword, part of
1 the test in an 'if' statement, part of any command executed in
1 a '&&' or '||' list except the command following the final
1 '&&' or '||', any command in a pipeline but the last, or if
1 the command's return status is being inverted with '!'. If a
1 compound command other than a subshell returns a non-zero
1 status because a command failed while '-e' was being ignored,
1 the shell does not exit. A trap on 'ERR', if set, is executed
1 before the shell exits.
1
1 This option applies to the shell environment and each subshell
11 environment separately (⇒Command Execution
Environment), and may cause subshells to exit before
1 executing all the commands in the subshell.
1
1 If a compound command or shell function executes in a context
1 where '-e' is being ignored, none of the commands executed
1 within the compound command or function body will be affected
1 by the '-e' setting, even if '-e' is set and a command returns
1 a failure status. If a compound command or shell function
1 sets '-e' while executing in a context where '-e' is ignored,
1 that setting will not have any effect until the compound
1 command or the command containing the function call completes.
1
1 '-f'
1 Disable filename expansion (globbing).
1
1 '-h'
1 Locate and remember (hash) commands as they are looked up for
1 execution. This option is enabled by default.
1
1 '-k'
1 All arguments in the form of assignment statements are placed
1 in the environment for a command, not just those that precede
1 the command name.
1
1 '-m'
1 Job control is enabled (⇒Job Control). All processes
1 run in a separate process group. When a background job
1 completes, the shell prints a line containing its exit status.
1
1 '-n'
1 Read commands but do not execute them. This may be used to
1 check a script for syntax errors. This option is ignored by
1 interactive shells.
1
1 '-o OPTION-NAME'
1
1 Set the option corresponding to OPTION-NAME:
1
1 'allexport'
1 Same as '-a'.
1
1 'braceexpand'
1 Same as '-B'.
1
1 'emacs'
11 Use an 'emacs'-style line editing interface (⇒
Command Line Editing). This also affects the editing
1 interface used for 'read -e'.
1
1 'errexit'
1 Same as '-e'.
1
1 'errtrace'
1 Same as '-E'.
1
1 'functrace'
1 Same as '-T'.
1
1 'hashall'
1 Same as '-h'.
1
1 'histexpand'
1 Same as '-H'.
1
1 'history'
11 Enable command history, as described in ⇒Bash
History Facilities. This option is on by default in
1 interactive shells.
1
1 'ignoreeof'
1 An interactive shell will not exit upon reading EOF.
1
1 'keyword'
1 Same as '-k'.
1
1 'monitor'
1 Same as '-m'.
1
1 'noclobber'
1 Same as '-C'.
1
1 'noexec'
1 Same as '-n'.
1
1 'noglob'
1 Same as '-f'.
1
1 'nolog'
1 Currently ignored.
1
1 'notify'
1 Same as '-b'.
1
1 'nounset'
1 Same as '-u'.
1
1 'onecmd'
1 Same as '-t'.
1
1 'physical'
1 Same as '-P'.
1
1 'pipefail'
1 If set, the return value of a pipeline is the value of
1 the last (rightmost) command to exit with a non-zero
1 status, or zero if all commands in the pipeline exit
1 successfully. This option is disabled by default.
1
1 'posix'
1 Change the behavior of Bash where the default operation
1 differs from the POSIX standard to match the standard
1 (⇒Bash POSIX Mode). This is intended to make Bash
1 behave as a strict superset of that standard.
1
1 'privileged'
1 Same as '-p'.
1
1 'verbose'
1 Same as '-v'.
1
1 'vi'
1 Use a 'vi'-style line editing interface. This also
1 affects the editing interface used for 'read -e'.
1
1 'xtrace'
1 Same as '-x'.
1
1 '-p'
1 Turn on privileged mode. In this mode, the '$BASH_ENV' and
1 '$ENV' files are not processed, shell functions are not
1 inherited from the environment, and the 'SHELLOPTS',
1 'BASHOPTS', 'CDPATH' and 'GLOBIGNORE' variables, if they
1 appear in the environment, are ignored. If the shell is
1 started with the effective user (group) id not equal to the
1 real user (group) id, and the '-p' option is not supplied,
1 these actions are taken and the effective user id is set to
1 the real user id. If the '-p' option is supplied at startup,
1 the effective user id is not reset. Turning this option off
1 causes the effective user and group ids to be set to the real
1 user and group ids.
1
1 '-t'
1 Exit after reading and executing one command.
1
1 '-u'
1 Treat unset variables and parameters other than the special
1 parameters '@' or '*' as an error when performing parameter
1 expansion. An error message will be written to the standard
1 error, and a non-interactive shell will exit.
1
1 '-v'
1 Print shell input lines as they are read.
1
1 '-x'
1 Print a trace of simple commands, 'for' commands, 'case'
1 commands, 'select' commands, and arithmetic 'for' commands and
1 their arguments or associated word lists after they are
1 expanded and before they are executed. The value of the 'PS4'
1 variable is expanded and the resultant value is printed before
1 the command and its expanded arguments.
1
1 '-B'
11 The shell will perform brace expansion (⇒Brace
Expansion). This option is on by default.
1
1 '-C'
1 Prevent output redirection using '>', '>&', and '<>' from
1 overwriting existing files.
1
1 '-E'
1 If set, any trap on 'ERR' is inherited by shell functions,
1 command substitutions, and commands executed in a subshell
1 environment. The 'ERR' trap is normally not inherited in such
1 cases.
1
1 '-H'
11 Enable '!' style history substitution (⇒History
Interaction). This option is on by default for interactive
1 shells.
1
1 '-P'
1 If set, do not resolve symbolic links when performing commands
1 such as 'cd' which change the current directory. The physical
1 directory is used instead. By default, Bash follows the
1 logical chain of directories when performing commands which
1 change the current directory.
1
1 For example, if '/usr/sys' is a symbolic link to
1 '/usr/local/sys' then:
1 $ cd /usr/sys; echo $PWD
1 /usr/sys
1 $ cd ..; pwd
1 /usr
1
1 If 'set -P' is on, then:
1 $ cd /usr/sys; echo $PWD
1 /usr/local/sys
1 $ cd ..; pwd
1 /usr/local
1
1 '-T'
1 If set, any trap on 'DEBUG' and 'RETURN' are inherited by
1 shell functions, command substitutions, and commands executed
1 in a subshell environment. The 'DEBUG' and 'RETURN' traps are
1 normally not inherited in such cases.
1
1 '--'
1 If no arguments follow this option, then the positional
1 parameters are unset. Otherwise, the positional parameters
1 are set to the ARGUMENTS, even if some of them begin with a
1 '-'.
1
1 '-'
1 Signal the end of options, cause all remaining ARGUMENTS to be
1 assigned to the positional parameters. The '-x' and '-v'
1 options are turned off. If there are no arguments, the
1 positional parameters remain unchanged.
1
1 Using '+' rather than '-' causes these options to be turned off.
1 The options can also be used upon invocation of the shell. The
1 current set of options may be found in '$-'.
1
1 The remaining N ARGUMENTS are positional parameters and are
1 assigned, in order, to '$1', '$2', ... '$N'. The special parameter
1 '#' is set to N.
1
1 The return status is always zero unless an invalid option is
1 supplied.
1