The set built-in sets shell options and positional parameters.


  • set [options] [operands]

  • set -o

  • set +o

The set built-in requires that all options precede operands. Any command line arguments after the first operand are all treated as operands.


When executed without any command arguments, the built-in prints a list of all existing variables to the standard input in a form that can be reused as commands that will restore the variable definitions.

When -o is the only command argument, the built-in prints a list of shell options with their current settings. When +o is the only command argument, the built-in prints commands that can be reused to restore the current shell option settings.

In other cases, the built-in changes shell option settings and/or positional parameters.


When one or more options are specified, the built-in enables or disables the shell options. A normal hyphen-prefixed option enables a shell option. An option that is prefixed with a plus (+) instead of a hyphen disables a shell option. For example, options -m, -o monitor, and --monitor enable the monitor option and options +m, +o monitor, ++monitor disable it.

The name of a long option is case-insensitive and may include irrelevant non-alphanumeric characters, which are ignored. For example, options --le-comp-debug and --LeCompDebug are equivalent. If no is prepended to the name of a long option, the meaning is reversed. For example, --noallexport is equivalent to ++allexport and ++nonotify to --notify.

An option can be specified in one of the following forms:

  • a long option e.g. --allexport

  • an -o option with a option name specified as the argument e.g. -o allexport

  • a single-character option e.g. -a

Not all options can be specified as single-character options.

The available options are:

all-export (-a)

When enabled, all variables are automatically exported when assigned.


This option enables brace expansion.


(Enabled by default) When enabled, pattern matching is case-sensitive in pathname expansion.

clobber (+C)

(Enabled by default) When enabled, the > redirection behaves the same as the >| redirection.


(Enabled by default) These options affect choice of the current job (cf. job ID).


When enabled, periods at the beginning of filenames are not treated specially in pathname expansion.


This option enables line-editing in the emacs mode.


When enabled, field splitting does not remove the last field even if it is empty.

err-exit (-e)

When enabled, if a pipeline ends with a non-zero exit status, the shell immediately exits unless:

exec (+n)

(Enabled by default) Commands are actually executed only when this option is enabled. Otherwise, commands are just parsed and not executed. Disabling this option may be useful for syntax checking. In an interactive shell, this option is always assumed enabled.


This option enables extension in pathname expansion.

glob (+f)

(Enabled by default) This option enables pathname expansion.

hash-on-def (-h)

When a function is defined when this option is enabled, the shell immediately performs command path search for each command that appears in the function and caches the command’s full path.


When enabled, command lines that start with a whitespace are not saved in command history.


When enabled, an interactive shell does not exit when EOF (end of file) is input. This prevents the shell from exiting when you accidentally hit Ctrl-D.


See shell options on line-editing.


When enabled, resulting directory names are suffixed by a slash in pathname expansion.

monitor (-m)

This option enables job control. This option is enabled by default for an interactive shell.

notify (-b)

When the status of a job changes when this option is enabled, the shell immediately notifies at any time. This option overrides the notify-le option.


This option is similar to the notify option, but the status change is notified only while the shell is waiting for input with line-editing.


When enabled, in pathname expansion, patterns that do not match any pathname are removed from the command line rather than left as is.


When enabled, the exit status of a pipeline is zero if and only if all the subcommands of the pipeline exit with an exit status of zero.


This option enables the POSIXly-correct mode.


(Enabled by default) When this option is disabled, the x-trace option is temporarily disabled while the shell is executing commands defined in the COMMAND_NOT_FOUND_HANDLER, PROMPT_COMMAND, or YASH_AFTER_CD variable.

unset (+u)

(Enabled by default) When enabled, undefined parameters are expanded to empty strings in parameter expansion. When disabled, expansion of undefined parameter results in an error.

verbose (-v)

When enabled, the shell prints each command line to the standard error before parsing and executing it.


This option enables line-editing in the vi mode. This option is enabled by default in an interactive shell if the standard input and error are both terminals.

x-trace (-x)

When enabled, the results of expansion are printed to the standard error for each simple command being executed. When printed, each line is prepended with an expansion result of the PS4 variable. See also the trace-all option.


If one or more operands are passed to the set built-in, current positional parameters are all removed and the operands are set as new positional parameters. If the -- separator (cf. syntax of command arguments) is passed, the positional parameters are set even when there are no operands, in which case new positional parameters will be nothing.

Exit status

The exit status of the set built-in is zero unless there is any error.


The set built-in is a special built-in.

In the POSIX standard, available shell options are much limited. The standard does not define:

  • long options such as --allexport,

  • prepending no to negate an option,

  • using uppercase letters and/or non-alphanumeric characters in option names

The options defined in the standard are:

  • -a, -o allexport

  • -e, -o errexit

  • -m, -o monitor

  • -C, -o noclobber

  • -n, -o noexec

  • -f, -o noglob

  • -b, -o notify

  • -u, -o nounset

  • -v, -o verbose

  • -x, -o xtrace

  • -h

  • -o ignoreeof

  • -o nolog

  • -o vi

Yash does not support the nolog option, which prevents function definitions from being added to command history.