The set builtin command

FIXME incomplete - text, examples, maybe extended description


set [--abefhkmnptuvxBCHP] <-o OPTIONNAME> [-][--] <POSPARAMS>


set is primarily made to

  • set the positional parameters (see handling positional parameters) to <POSPARAMS>
  • set shell attributes with short options (see below)
  • set shell attributes with long option names (see below)

Without any options, set displays all shell- and environment-variables (only is POSIX-mode) in a re-usable format NAME=VALUE.


All attributes below can be switched on using -X and switched off using +X. This is done because of the historical meaning of the - to set flags (true for most commands on UNIX®).

-aallexportAutomatically mark new and altered variables to be exported to subsequent environments.
-bnotifyDon't wait for the next prompt to print when showing the reports for a terminated background job (only with job control)
-eerrexitWhen set, the shell exits when a simple command in a command list exits non-zero (FALSE). This is not done in situations, where the exit code is already checked (if, while, until, ||, &&)
-fnoglobDisable pathname expansion (globbing)
-hhashallRemembers the location of commands when they're called (hashing). Enabled by default.
-kkeywordAllows to place environment-assignments everywhere in the commandline, not only infront of the called command.
-mmonitorMonitor mode. With job control, a short descriptive line is printed when a backgroud job ends. Default is "on" for interactive shells (with job control).
-nnoexecRead and parse but do not execute commands - useful for checking scripts for syntax errors. Ignored by interactive shells.
-o Set/unset attributes with long option names, e.g. set -o noglob. The long option names are in the second column of this table. If no option name is given, all options are printed with their current status.
-pprivilegedTurn on privileged mode.
-tonecmdExit after reading and executing one command.
-unounsetTreat unset variables as an error when performing parameter expansion. Non-interactive shells exit on this error.
-vverbosePrint shell input lines as they are read - useful for debugging.
-xxtracePrint commands just before execution - with all expansions and substitutions done, and words marked - useful for debugging.
-BbraceexpandThe shell performs brace expansion This is on by default.
-CnoclobberDon't overwrite files on redirection operations. You can override that by specifying the >| redirection operator when needed. See redirection
-EerrtraceERR-traps are inherited by by shell functions, command substitutions, and commands executed in a subshell environment.
-HhistexpandEnable !-style history expansion. Defaults to on for interactive shells.
-PphysicalDon't follow symlinks when changing directories - use the physical filesystem structure.
-TfunctraceDEBUG- and RETURN-traps are inherited by subsequent environments, like -E for ERR trap.
- "End of options" - all following arguments are assigned to the positional parameters, even when they begin with a dash. -x and -v options are turned off. Positional parameters are unchanged (unlike using --!) when no further arguments are given.
-- If no arguments follow, the positional parameters are unset. With arguments, the positional parameters are set, even if the strings begin with a - (dash) like an option.
Long options usable with -o without a short equivalent
emacsUse an emacs-style command line editing interface. This is enabled by default when the shell is interactive, unless the shell is started with –noediting option.
historyIf set, command historization is done (enabled by default on interactive shells)
ignoreeofThe effect is as if the shell command IGNOREEOF=10 had been executed. See shell variables.
nolog(currently ignored)
pipefailIf set, the exit code from a pipeline is different from the normal ("last command in pipeline") behaviour: TRUE when no command failed, FALSE when something failed (code of the rightmost command that failed)
posixWhen set, Bash runs in POSIX mode.
viEnables a vi-style command line editing interface.


Tag a part of a shell script to output debugging information (-x):

set -x # on
set +x # off

Portability considerations

set and its basic behaviour and options are specified by POSIX®. However, options that influence Bash-specific things are not portable, naturally.

See also


Enter your comment. Wiki syntax is allowed:
commands/builtin/set.txt · Last modified: 2011/03/21 03:50 by fgrose

Fatal error: Out of memory (allocated 35913728) (tried to allocate 40 bytes) in /homepages/41/d13525936/htdocs/bash-hackers-site/wiki/lib/plugins/quickstats/db/php-local-browscap.php on line 15