ZSHOPTIONS(1)

๐ŸŽ€ ZSHOPTIONS(1) โ€” zshoptions ๐ŸŽ€

Manual name folded in near the top: zshoptions โ€” zsh options, from the General Commands Manual. Bestie, this is the full option lore, and every single flag is still here. ๐Ÿ’…โœจ

๐ŸŒธ NAME ๐ŸŒธ

zshoptions โ€” zsh options.

๐Ÿ’ซ SPECIFYING OPTIONS ๐Ÿ’ซ

Options are mostly referred to by name, and those names are case insensitive with underscores literally ignored. Like, allexport is equivalent to A__lleXP_ort. No cap. ๐Ÿซถ

You can flip the sense of an option name by putting no in front of it, so setopt No_Beep is equivalent to unsetopt beep. The inversion can only happen once, so nonobeep is not a synonym for beep. Same energy: tify is not a synonym for nonotify (which is the inversion of notify). ๐Ÿ’€

Some options also have one or more single-letter names. There are two sets of single-letter options: one used by default, and another used to emulate sh/ksh (used when the SH_OPTION_LETTERS option is set). Single-letter options can be used on the shell command line, or with the set, setopt and unsetopt builtins, as normal Unix options preceded by -. ๐ŸŽ€

You can invert the sense of single-letter options by using + instead of -. Some single-letter option names refer to an option being off, in which case the inversion of that name refers to the option being on. For example, +n is the short name of exec, and -n is the short name of its inversion, noexec. ๐Ÿ‘‘

In strings of single-letter options supplied to the shell at startup, trailing whitespace is ignored; for example the string -f will be treated just as -f, but the string -f i is an error. Why? Because many systems that implement the #! mechanism for calling scripts do not strip trailing whitespace. ๐Ÿ™ˆ

It is possible for options to be set within a function scope. See the description of the option LOCAL_OPTIONS below. ๐Ÿงš

๐Ÿ”ฅ DESCRIPTION OF OPTIONS ๐Ÿ”ฅ

In the following list, options set by default in all emulations are marked <D>; those set by default only in csh, ksh, sh, or zsh emulations are marked <C>, <K>, <S>, <Z> as appropriate. When listing options (by setopt, unsetopt, set -o or set +o), those turned on by default appear in the list prefixed with no. Hence (unless KSH_OPTION_PRINT is set), setopt shows all options whose settings are changed from the default. โœจ

๐Ÿšช Changing Directories ๐Ÿšช

  • AUTO_CD (-J) โ€” If a command is issued that can't be executed as a normal command, and the command is the name of a directory, perform the cd command to that directory. This option is only applicable if the option SHIN_STDIN is set, i.e. if commands are being read from standard input. The option is designed for interactive use; it is recommended that cd be used explicitly in scripts to avoid ambiguity. ๐Ÿšช
  • AUTO_PUSHD (-N) โ€” Make cd push the old directory onto the directory stack. ๐Ÿ“š
  • CDABLE_VARS (-T) โ€” If the argument to a cd command (or an implied cd with the AUTO_CD option set) is not a directory, and does not begin with a slash, try to expand the expression as if it were preceded by a ~ (see the section Filename Expansion). ๐Ÿ 
  • CD_SILENT โ€” Never print the working directory after a cd (whether explicit or implied with the AUTO_CD option set). cd normally prints the working directory when the argument given to it was -, a stack entry, or the name of a directory found under CDPATH. Note that this is distinct from pushd's stack-printing behaviour, which is controlled by PUSHD_SILENT. This option overrides the printing-related effects of POSIX_CD. ๐Ÿคซ
  • CHASE_DOTS โ€” When changing to a directory containing a path segment .. which would otherwise be treated as canceling the previous segment in the path (in other words, foo/.. would be removed from the path, or if .. is the first part of the path, the last part of the current working directory would be removed), instead resolve the path to the physical directory. This option is overridden by CHASE_LINKS. For example, suppose /foo/bar is a link to the directory /alt/rod. Without this option set, cd /foo/bar/.. changes to /foo; with it set, it changes to /alt. The same applies if the current directory is /foo/bar and cd .. is used. Note that all other symbolic links in the path will also be resolved. ๐ŸŒ€
  • CHASE_LINKS (-w) โ€” Resolve symbolic links to their true values when changing directory. This also has the effect of CHASE_DOTS, i.e. a .. path segment will be treated as referring to the physical parent, even if the preceding path segment is a symbolic link. ๐Ÿ”—
  • POSIX_CD <K> <S> โ€” Modifies the behaviour of cd, chdir and pushd commands to make them more compatible with the POSIX standard. The behaviour with the option unset is described in the documentation for the cd builtin in zshbuiltins(1). If the option is set, the shell does not test for directories beneath the local directory (.) until after all directories in cdpath have been tested, and the cd and chdir commands do not recognise arguments of the form {+|-}n as directory stack entries. Also, if the option is set, the conditions under which the shell prints the new directory after changing to it are modified. It is no longer restricted to interactive shells (although printing of the directory stack with pushd is still limited to interactive shells); and any use of a component of CDPATH, including a . but excluding an empty component that is otherwise treated as ., causes the directory to be printed. ๐Ÿ“œ
  • PUSHD_IGNORE_DUPS โ€” Don't push multiple copies of the same directory onto the directory stack. ๐Ÿšซ
  • PUSHD_MINUS โ€” Exchanges the meanings of + and - when used with a number to specify a directory in the stack. โž•โž–
  • PUSHD_SILENT (-E) โ€” Do not print the directory stack after pushd or popd. ๐Ÿค
  • PUSHD_TO_HOME (-D) โ€” Have pushd with no arguments act like pushd $HOME. ๐Ÿก

โœจ Completion โœจ

  • ALWAYS_LAST_PROMPT <D> โ€” If unset, key functions that list completions try to return to the last prompt if given a numeric argument. If set these functions try to return to the last prompt if given no numeric argument. โ†ฉ๏ธ
  • ALWAYS_TO_END โ€” If a completion is performed with the cursor within a word, and a full completion is inserted, the cursor is moved to the end of the word. That is, the cursor is moved to the end of the word if either a single match is inserted or menu completion is performed. ๐Ÿ
  • AUTO_LIST (-9) <D> โ€” Automatically list choices on an ambiguous completion. ๐Ÿ“‹
  • AUTO_MENU <D> โ€” Automatically use menu completion after the second consecutive request for completion, for example by pressing the tab key repeatedly. This option is overridden by MENU_COMPLETE. ๐Ÿ“‘
  • AUTO_NAME_DIRS โ€” Any parameter that is set to the absolute name of a directory immediately becomes a name for that directory, that will be used by the %~ and related prompt sequences, and will be available when completion is performed on a word starting with ~. (Otherwise, the parameter must be used in the form ~param first.) ๐Ÿท๏ธ
  • AUTO_PARAM_KEYS <D> โ€” If a parameter name was completed and a following character (normally a space) automatically inserted, and the next character typed is one of those that have to come directly after the name (like }, :, etc.), the automatically added character is deleted, so that the character typed comes immediately after the parameter name. Completion in a brace expansion is affected similarly: the added character is a ,, which will be removed if } is typed next. โŒจ๏ธ
  • AUTO_PARAM_SLASH <D> โ€” If a parameter is completed whose content is the name of a directory, then add a trailing slash instead of a space. / โœจ
  • AUTO_REMOVE_SLASH <D> โ€” When the last character resulting from a completion is a slash and the next character typed is a word delimiter, a slash, or a character that ends a command (such as a semicolon or an ampersand), remove the slash. โœ‚๏ธ
  • BASH_AUTO_LIST โ€” On an ambiguous completion, automatically list choices when the completion function is called twice in succession. This takes precedence over AUTO_LIST. The setting of LIST_AMBIGUOUS is respected. If AUTO_MENU is set, the menu behaviour will then start with the third press. Note that this will not work with MENU_COMPLETE, since repeated completion calls immediately cycle through the list in that case. ๐Ÿš
  • COMPLETE_ALIASES โ€” Prevents aliases on the command line from being internally substituted before completion is attempted. The effect is to make the alias a distinct command for completion purposes. ๐Ÿท๏ธ
  • COMPLETE_IN_WORD โ€” If unset, the cursor is set to the end of the word if completion is started. Otherwise it stays there and completion is done from both ends. โ†”๏ธ
  • GLOB_COMPLETE โ€” When the current word has a glob pattern, do not insert all the words resulting from the expansion but generate matches as for completion and cycle through them like MENU_COMPLETE. The matches are generated as if a * was added to the end of the word, or inserted at the cursor when COMPLETE_IN_WORD is set. This actually uses pattern matching, not globbing, so it works not only for files but for any completion, such as options, user names, etc. Note that when the pattern matcher is used, matching control (for example, case-insensitive or anchored matching) cannot be used. This limitation only applies when the current word contains a pattern; simply turning on the GLOB_COMPLETE option does not have this effect. ๐ŸŒŸ
  • HASH_LIST_ALL <D> โ€” Whenever a command completion or spelling correction is attempted, make sure the entire command path is hashed first. This makes the first completion slower but avoids false reports of spelling errors. ๐Ÿ—‚๏ธ
  • LIST_AMBIGUOUS <D> โ€” This option works when AUTO_LIST or BASH_AUTO_LIST is also set. If there is an unambiguous prefix to insert on the command line, that is done without a completion list being displayed; in other words, auto-listing behaviour only takes place when nothing would be inserted. In the case of BASH_AUTO_LIST, this means that the list will be delayed to the third call of the function. ๐Ÿ’–
  • LIST_BEEP <D> โ€” bestie, this one makes the shell beep when your completion is ambiguous ๐Ÿ˜ญ Like, more accurately: it forces the completion widgets to return status 1 on an ambiguous completion, which is what makes the shell go beep if the BEEP option is also set. This may get modified if completion is called from a user-defined widget, iykyk.
  • LIST_PACKED โ€” tries to make the completion list smaller, occupying less lines, by printing the matches in columns with different widths ๐ŸŽ€ compact queen behaviour.
  • LIST_ROWS_FIRST โ€” lays out the matches in completion lists sorted horizontally, meaning the second match sits to the right of the first one, not under it like usual ๐Ÿฆ‹ it's giving row-major, not column-major.
  • LIST_TYPES (-X) <D> โ€” when it's listing files that are possible completions, it shows you the type of each file with a trailing identifying mark โœจ little tag on every file, adorable.
  • MENU_COMPLETE (-Y) โ€” on an ambiguous completion, instead of listing possibilities or beeping, it just inserts the first match immediately ๐Ÿ”ฅ Then when you request completion again, it removes the first match and inserts the second, etc. When there are no more matches, it goes back to the first one again. reverse-menu-complete can be used to loop through the list in the other direction. This option overrides AUTO_MENU. main character energy, honestly.
  • REC_EXACT (-S) โ€” if the string on the command line exactly matches one of the possible completions, it gets accepted, even if there's another completion (i.e. that string with something else added) that also matches ๐Ÿ‘‘

Expansion and Globbing ๐ŸŒ€โœจ

  • BAD_PATTERN (+2) <C> <Z> โ€” if a pattern for filename generation is badly formed, print an error message. (If this option is unset, the pattern is just left unchanged, lowkey pretending nothing happened ๐Ÿ™ˆ)
  • BARE_GLOB_QUAL <Z> โ€” in a glob pattern, treat a trailing set of parentheses as a qualifier list, if it contains no |, ( or (if special) ~ characters. See the section Filename Generation.
  • BRACE_CCL โ€” expands expressions in braces which would not otherwise undergo brace expansion to a lexically ordered list of all the characters ๐Ÿ’… See the section Brace Expansion.
  • CASE_GLOB <D> โ€” makes globbing (filename generation) sensitive to case. Note that other uses of patterns are always sensitive to case. If the option is unset, the presence of any character which is special to filename generation will cause case-insensitive matching. For example, cvs(/) can match the directory CVS owing to the presence of the globbing flag (unless the option BARE_GLOB_QUAL is unset).
  • CASE_MATCH <D> โ€” makes regular expressions using the zsh/regex module (including matches with =~) sensitive to case ๐ŸŽ€
  • CASE_PATHS โ€” if CASE_PATHS is not set (the default), CASE_GLOB affects the interpretation of every path component, whenever a special character appears in any component. When CASE_PATHS is set, file path components that do not contain special filename generation characters are always sensitive to case, thus restricting NO_CASE_GLOB to components that contain globbing characters.

Note that if the filesystem itself is not sensitive to case, then CASE_PATHS has no effect ๐Ÿ™ˆ

  • CSH_NULL_GLOB <C> โ€” if a pattern for filename generation has no matches, delete the pattern from the argument list; don't report an error unless all the patterns in a command have no matches. Overrides NOMATCH.
  • EQUALS <Z> โ€” performs = filename expansion. (See the section Filename Expansion.)
  • EXTENDED_GLOB โ€” treats the #, ~ and ^ characters as part of patterns for filename generation, etc. (An initial unquoted ~ always produces named directory expansion.) โœจ fancy pattern mode activated.
  • FORCE_FLOAT โ€” constants in arithmetic evaluation will be treated as floating point even without the use of a decimal point; the values of integer variables will be converted to floating point when used in arithmetic expressions. Integers in any base will be converted ๐Ÿ”ข float era.
  • GLOB (+F, ksh: +f) <D> โ€” performs filename generation (globbing). (See the section Filename Generation.)
  • GLOB_ASSIGN <C> โ€” if this option is set, filename generation (globbing) is performed on the right hand side of scalar parameter assignments of the form name=pattern (e.g. foo=*). If the result has more than one word the parameter will become an array with those words as arguments. This option is provided for backwards compatibility only ๐Ÿ’€ globbing is always performed on the right hand side of array assignments of the form name=(value) (e.g. foo=(*)) and this form is recommended for clarity; with this option set, it is not possible to predict whether the result will be an array or a scalar. No cap, unpredictable, don't do it.
  • GLOB_DOTS (-4) โ€” do not require a leading . in a filename to be matched explicitly ๐Ÿซถ hidden files, come through.
  • GLOB_STAR_SHORT โ€” when this option is set and the default zsh-style globbing is in effect, the pattern **/* can be abbreviated to ** and the pattern ***/* can be abbreviated to ***. Hence **.c finds a file ending in .c in any subdirectory, and ***.c does the same while also following symbolic links. A / immediately after the ** or *** forces the pattern to be treated as the unabbreviated form โญ
  • GLOB_SUBST <C> <K> <S> โ€” treats any characters resulting from parameter expansion as being eligible for filename expansion and filename generation, and any characters resulting from command substitution as being eligible for filename generation. Braces (and commas in between) do not become eligible for expansion.
  • HIST_SUBST_PATTERN โ€” substitutions using the :s and :& history modifiers are performed with pattern matching instead of string matching ๐Ÿ’… This occurs wherever history modifiers are valid, including glob qualifiers and parameters. See the section Modifiers in zshexpn(1).
  • IGNORE_BRACES (-I) <S> โ€” do not perform brace expansion. For historical reasons this also includes the effect of the IGNORE_CLOSE_BRACES option.
  • IGNORE_CLOSE_BRACES โ€” when neither this option nor IGNORE_BRACES is set, a sole close brace character } is syntactically significant at any point on a command line. This has the effect that no semicolon or newline is necessary before the brace terminating a function or current shell construct. When either option is set, a closing brace is syntactically significant only in command position. Unlike IGNORE_BRACES, this option does not disable brace expansion.

For example, with both options unset a function may be defined in the following fashion:

args() { echo $# }

while if either option is set, this does not work and something equivalent to the following is required:

args() { echo $#; }

๐Ÿ˜ญ the semicolon jumpscare, I know.

  • KSH_GLOB <K> โ€” in pattern matching, the interpretation of parentheses is affected by a preceding @, *, +, ? or !. See the section Filename Generation.
  • MAGIC_EQUAL_SUBST โ€” all unquoted arguments of the form anything=expression appearing after the command name have filename expansion (that is, where expression has a leading ~ or =) performed on expression as if it were a parameter assignment ๐ŸŒธ The argument is not otherwise treated specially; it is passed to the command as a single argument, and not used as an actual parameter assignment. For example, in echo foo=~/bar:~/rod, both occurrences of ~ would be replaced. Note that this happens anyway with typeset and similar statements.

This option respects the setting of the KSH_TYPESET option. In other words, if both options are in effect, arguments looking like assignments will not undergo word splitting ๐ŸŽ€

  • MARK_DIRS (-8, ksh: -X) โ€” appends a trailing / to all directory names resulting from filename generation (globbing) ๐Ÿฆ‹ lil slash so you know it's a dir.
  • MULTIBYTE <D> โ€” respect multibyte characters when found in strings. When this option is set, strings are examined using the system library to determine how many bytes form a character, depending on the current locale. This affects the way characters are counted in pattern matching, parameter values and various delimiters.

The option is on by default if the shell was compiled with MULTIBYTE_SUPPORT; otherwise it is off by default and has no effect if turned on.

If the option is off a single byte is always treated as a single character. This setting is designed purely for examining strings known to contain raw bytes or other values that may not be characters in the current locale. It is not necessary to unset the option merely because the character set for the current locale does not contain multibyte characters ๐Ÿ™ˆ

The option does not affect the shell's editor, which always uses the locale to determine multibyte characters. This is because the character set displayed by the terminal emulator is independent of shell settings. iykyk.

  • NOMATCH (+3) <C> <Z> โ€” if a pattern for filename generation has no matches, print an error, instead of leaving it unchanged in the argument list. This also applies to file expansion of an initial ~ or =.
  • NULL_GLOB (-G) โ€” if a pattern for filename generation has no matches, delete the pattern from the argument list instead of reporting an error. Overrides NOMATCH ๐Ÿ’€ nothing to see here.
  • NUMERIC_GLOB_SORT โ€” if numeric filenames are matched by a filename generation pattern, sort the filenames numerically rather than lexicographically ๐Ÿ”ข so 2 comes before 10, slay.
  • RC_EXPAND_PARAM (-P) โ€” array expansions of the form foo${xx}bar, where the parameter xx is set to (a b c), are substituted with fooabar foobbar foocbar instead of the default fooa b cbar โœจ Note that an empty array will therefore cause all arguments to be removed ๐Ÿ™ˆ careful bestie.
  • REMATCH_PCRE โ€” if set, regular expression matching with the =~ operator will use Perl-Compatible Regular Expressions from the PCRE library. (The zsh/pcre module must be available.) If not set, regular expressions will use the extended regexp syntax provided by the system libraries ๐ŸŒˆ
  • SH_GLOB <K> <S> โ€” this one disables the โœจspecialโœจ meaning of '(', '|', ')' and '<' when globbing the result of parameter and command substitutions, and also in some other places where the shell accepts patterns. If SH_GLOB is set but KSH_GLOB is not, the shell allows subshell expressions in parentheses to be interpreted in some cases where there's no space before the opening paren โ€” e.g. !(true) gets read as if there were a space after the !. ๐Ÿ’… This option is set by default if zsh is invoked as sh or ksh.
  • UNSET (+u, ksh: +u) <K> <S> <Z> โ€” treat unset parameters as if they were empty when substituting, and as if they were zero when reading their values in arithmetic expansion and arithmetic commands. Otherwise they're treated as an error ๐Ÿ˜ญ.
  • WARN_CREATE_GLOBAL โ€” prints a warning message when a global parameter gets created inside a function by an assignment or in math context. This often means a parameter wasn't declared local when it 100% should have been. Parameters explicitly declared global from within a function using typeset -g do not cause a warning, no cap. ๐Ÿ‘€ Note that there's no warning when a local parameter is assigned to in a nested function โ€” which, ngl, may also indicate an error.
  • WARN_NESTED_VAR โ€” prints a warning message when an existing parameter from an enclosing function scope, or a global, gets set in a function by an assignment or in math context. Assignment to shell special parameters does not cause a warning. This is the companion to WARN_CREATE_GLOBAL โ€” as in, here the warning is only printed when a parameter is not created ๐Ÿซถ. Where possible, using typeset -g to set the parameter suppresses the error, but bestie, note that this needs to be used every time the parameter is set. To restrict the effect of this option to a single function scope, use functions -W.

For example, the following code produces a warning for the assignment inside the function nested, as that overrides the value within toplevel:

toplevel() {
  local foo="in fn"
  nested
}
nested() {
     foo="in nested"
}
setopt warn_nested_var
toplevel

๐Ÿ•ฐ๏ธ History

  • APPEND_HISTORY <D> โ€” if this is set, zsh sessions will append their history list to the history file instead of replacing it. So multiple parallel zsh sessions all have the new entries from their history lists added to the history file, in the order that they exit. ๐Ÿ”ฅ The file will still be periodically re-written to trim it when the number of lines grows 20% beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY option).
  • BANG_HIST (+K) <C> <Z> โ€” perform textual history expansion, csh-style, treating the character '!' specially. Bang bang, it's giving classic ๐Ÿ’ฅ.
  • EXTENDED_HISTORY <C> โ€” save each command's beginning timestamp (in seconds since the epoch) and the duration (in seconds) to the history file. The format of this prefixed data is:
': <beginning time>:<elapsed seconds>;<command>'.
  • HIST_ALLOW_CLOBBER โ€” add '|' to output redirections in the history. This allows history references to clobber files even when CLOBBER is unset. ๐Ÿ™ˆ
  • HIST_BEEP <D> โ€” beep in ZLE when a widget attempts to access a history entry that isn't there.
  • HIST_EXPIRE_DUPS_FIRST โ€” if the internal history needs to be trimmed to add the current command line, setting this option makes the oldest history event that has a duplicate get lost before losing a unique event from the list. You should be sure to set the value of HISTSIZE to a larger number than SAVEHIST so you've got some room for the duplicated events โ€” otherwise this option will behave just like HIST_IGNORE_ALL_DUPS once the history fills up with unique events. ๐Ÿ’€
  • HIST_FCNTL_LOCK โ€” when writing out the history file, zsh by default uses ad-hoc file locking to avoid known problems with locking on some operating systems. With this option, locking is done by means of the system's fcntl call, where this method is available. On recent operating systems this may provide better performance, in particular avoiding history corruption when files are stored on NFS. ๐Ÿ‘‘
  • HIST_FIND_NO_DUPS โ€” when searching for history entries in the line editor, do not display duplicates of a line previously found, even if the duplicates aren't contiguous.
  • HIST_IGNORE_ALL_DUPS โ€” if a new command line being added to the history list duplicates an older one, the older command is removed from the list (even if it's not the previous event).
  • HIST_IGNORE_DUPS (-h) โ€” do not enter command lines into the history list if they're duplicates of the previous event.
  • HIST_IGNORE_SPACE (-g) โ€” remove command lines from the history list when the first character on the line is a space, or when one of the expanded aliases contains a leading space. Only normal aliases have this behaviour โ€” not global or suffix aliases, ok? Note that the command lingers in the internal history until the next command is entered before it vanishes, which lets you briefly reuse or edit the line ๐ŸŽ€. If you want it to vanish right away without entering another command, type a space and press return.
  • HIST_LEX_WORDS โ€” by default, shell history read in from files is split into words on all white space. That means arguments with quoted whitespace aren't correctly handled, and consequently references to words in history lines that have been read from a file may be inaccurate ๐Ÿ˜ฌ. When this option is set, words read in from a history file are divided up in a similar fashion to normal shell command line handling. Although this produces more accurately delimited words, if the size of the history file is large this can be slow. Trial and error is necessary to decide, fr fr.
  • HIST_NO_FUNCTIONS โ€” remove function definitions from the history list. Note that the function lingers in the internal history until the next command is entered before it vanishes, letting you briefly reuse or edit the definition โœจ.
  • HIST_NO_STORE โ€” remove the history (fc -l) command from the history list when invoked. Note that the command lingers in the internal history until the next command is entered before it vanishes, letting you briefly reuse or edit the line.
  • HIST_REDUCE_BLANKS โ€” remove superfluous blanks from each command line being added to the history list. Clean girl aesthetic for your history ๐Ÿงš.
  • HIST_SAVE_BY_COPY <D> โ€” when the history file is re-written, zsh normally writes out a copy of the file named $HISTFILE.new and then renames it over the old one. If this option is unset, though, it instead truncates the old history file and writes out the new version in-place. If one of the history-appending options is enabled, this option only has an effect when the enlarged history file needs to be re-written to trim it down to size. Disable this only if you have special needs โ€” because doing so makes it possible to lose history entries if zsh gets interrupted during the save ๐Ÿ˜ญ.

When writing out a copy of the history file, zsh preserves the old file's permissions and group information, but will refuse to write out a new file if it would change the history file's owner.

  • HIST_SAVE_NO_DUPS โ€” when writing out the history file, older commands that duplicate newer ones are omitted.
  • HIST_VERIFY โ€” whenever the user enters a line with history expansion, don't execute the line directly; instead, perform history expansion and reload the line into the editing buffer. Preview era ๐Ÿ’….
  • INC_APPEND_HISTORY โ€” works like APPEND_HISTORY except that new history lines are added to the $HISTFILE incrementally (as soon as they're entered), rather than waiting until the shell exits. The file will still be periodically re-written to trim it when the number of lines grows 20% beyond the value specified by $SAVEHIST (see also the HIST_SAVE_BY_COPY option).
  • INC_APPEND_HISTORY_TIME โ€” a variant of INC_APPEND_HISTORY in which, where possible, the history entry is written out to the file after the command is finished, so the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY format. That means the history entry will not be available immediately from other instances of the shell that are using the same history file. ๐Ÿ‘€
This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive. Pick a lane, bestie.
  • SHARE_HISTORY <K> โ€” this option both imports new commands from the history file and causes your typed commands to be appended to the history file (that latter bit is like specifying INC_APPEND_HISTORY, which should be turned off if this option is in effect). The history lines are also output with timestamps ร  la EXTENDED_HISTORY, which makes it easier to find the spot where we left off reading the file after it gets re-written ๐Ÿซถ.

By default, history movement commands visit the imported lines as well as the local lines, but you can toggle this on and off with the set-local-history zle binding. It's also possible to create a zle widget that will make some commands ignore imported commands, and some include them. Main character energy for your keybindings, honestly.

If you find you want more control over when commands get imported, you may wish to turn SHARE_HISTORY off, turn INC_APPEND_HISTORY or INC_APPEND_HISTORY_TIME (see above) on, and then manually import commands whenever you need them using fc -RI. ๐Ÿฆ‹


๐ŸŒฑ Initialisation

  • ALL_EXPORT (-a, ksh: -a) โ€” all parameters subsequently defined are automatically exported. Set it and forget it, iconic.
  • GLOBAL_EXPORT <Z> โ€” okay so if this is set, then when you pass -x to the builtins declare, float, integer, readonly and typeset (but not local), it also quietly sets the -g flag โœจ. Which means parameters you export to the environment won't get made local to the enclosing function โ€” unless they already were, or you explicitly hand it +g. If this option is unset, exported parameters get made local exactly like any other parameter. No cap.
Lowkey a legacy thing: this one is set by default for backward compatibility, and it is not recommended that you rely on its behaviour. Also heads up โ€” the builtin export always sets both the -x and -g flags, so its effect reaches beyond the scope of the enclosing function. That's the most portable way to get this behaviour, periodt. ๐Ÿ’…
  • GLOBAL_RCS, +d <D> โ€” if this is unset, the startup files /etc/zsh/zprofile, /etc/zsh/zshrc, /etc/zsh/zlogin and /etc/zsh/zlogout will not be run ๐Ÿ™…. You can disable and re-enable it whenever you want, including from inside your local startup files (.zshrc, etc.).
  • RCS, +f <D> โ€” after /etc/zsh/zshenv gets sourced on startup, this is what makes the shell source .zshenv, /etc/zsh/zprofile, .zprofile, /etc/zsh/zshrc, .zshrc, /etc/zsh/zlogin, .zlogin, and .zlogout, as described in the section Files ๐ŸŒธ. If it's unset, /etc/zsh/zshenv still gets sourced, but none of the others do. You can set it at any time to stop the remaining startup files after the currently executing one from being sourced. Sneaky but valid.

๐ŸŒˆ Input/Output ๐ŸŒˆ

  • ALIASES <D> โ€” expand aliases. That's it. That's the whole vibe. ๐ŸŽ€
  • CLOBBER, +C, ksh: +C <D> โ€” lets > redirection truncate existing files ๐Ÿซถ. Otherwise you gotta use >! or >| to truncate a file.

And if this option is not set, and APPEND_CREATE is also not set, then you must use >>! or >>| to create a file. But if either option is set, >> is allowed. Simple as.

  • CLOBBER_EMPTY โ€” bestie read carefully, this one is only used if CLOBBER is not set. (Note: it is set by default.) If it's set, then regular files of zero length may be overwritten (clobbered) ๐Ÿ‘‘. But โš ๏ธ note that it's possible another process has written to the file between this test and the use of the file by the current process. So don't use this option in cases where files to be clobbered may be written to asynchronously. Safety first, always.
  • CORRECT, -0 โ€” try to correct the spelling of commands โœจ. Note that when the HASH_LIST_ALL option is not set, or when some directories in the path are not readable, this may falsely report spelling errors the first time some commands are used ๐Ÿ˜ญ. Not its fault, honestly.

You can set the shell variable CORRECT_IGNORE to a pattern that matches words which will never be offered as corrections. Protect your faves. ๐Ÿ’–

  • CORRECT_ALL, -O โ€” try to correct the spelling of all the arguments in a line. Ambitious icon behaviour ๐Ÿ’….

The shell variable CORRECT_IGNORE_FILE can be set to a pattern matching file names that will never be offered as corrections.

  • DVORAK โ€” use the Dvorak keyboard instead of the standard qwerty keyboard as the basis for examining spelling mistakes for the CORRECT and CORRECT_ALL options and the spell-word editor command โŒจ๏ธ. Keyboard layout rep era.
  • FLOW_CONTROL <D> โ€” if unset, output flow control via start/stop characters (usually assigned to ^S/^Q) is disabled in the shell's editor ๐Ÿฆ‹.
  • IGNORE_EOF, -7 โ€” do not exit on end-of-file ๐Ÿ›‘. You gotta use exit or logout instead. But fair warning: ten consecutive EOFs will cause the shell to exit anyway, so it doesn't just hang forever if its tty goes away.

Also, if this option is set and the Zsh Line Editor is used, widgets implemented by shell functions can be bound to EOF (normally Control+D) without printing the normal warning message ๐ŸŽ€. This works only for normal widgets โ€” not completion widgets. Iykyk.

  • INTERACTIVE_COMMENTS, -k <K> <S> โ€” allow comments even in interactive shells ๐Ÿ’ฌ. Yes queen, leave notes to yourself.
  • HASH_CMDS <D> โ€” note the location of each command the first time it is executed ๐Ÿง . Subsequent invocations of the same command use the saved location, avoiding a path search. If this option is unset, no path hashing is done at all. But! When CORRECT is set, commands whose names do not appear in the functions or aliases hash tables are hashed in order to avoid reporting them as spelling errors. Clever girl.
  • HASH_DIRS <D> โ€” whenever a command name is hashed, hash the directory containing it, plus all the directories that occur earlier in the path ๐Ÿ—‚๏ธ. Has no effect if neither HASH_CMDS nor CORRECT is set. Zero. Nada.
  • HASH_EXECUTABLES_ONLY โ€” when hashing commands because of HASH_CMDS, check that the file to be hashed is actually an executable ๐Ÿ”. This option is unset by default, because if the path contains a large number of commands, or consists of many remote files, those extra tests can take a long time ๐Ÿ˜ญ. Trial and error is needed to show if this option is beneficial โ€” literally you have to vibe-check it yourself.
  • MAIL_WARNING, -U โ€” print a warning message if a mail file has been accessed since the shell last checked ๐Ÿ“ฌ.
  • PATH_DIRS, -Q โ€” perform a path search even on command names with slashes in them ๐ŸŒŸ. So like, if /usr/local/bin is in the user's path and they type X11/xinit, the command /usr/local/bin/X11/xinit will be executed (assuming it exists). Commands explicitly beginning with /, ./ or ../ are not subject to the path search. This also applies to the . and source builtins.
๐Ÿ‘€ Note that subdirectories of the current directory are always searched for executables specified in this form. This takes place before any search indicated by this option, and regardless of whether . or the current directory appear in the command search path.
  • PATH_SCRIPT <K> <S> โ€” if this option is not set, a script passed as the first non-option argument to the shell must contain the name of the file to open ๐ŸŽ€. If this option is set, and the script does not specify a directory path, the script is looked for first in the current directory, then in the command path. See the section INVOCATION in zsh(1). Receipts in the docs, always.
  • PRINT_EIGHT_BIT โ€” print eight bit characters literally in completion lists, etc. ๐Ÿ–จ๏ธ This option is not necessary if your system correctly returns the printability of eight bit characters (see ctype(3)).
  • PRINT_EXIT_VALUE, -1 โ€” print the exit value of programs with non-zero exit status ๐Ÿ“Š. This is only available at the command line in interactive shells.
  • RC_QUOTES โ€” allow the character sequence ''' to signify a single quote within singly quoted strings ๐Ÿ™ˆ. Note this does not apply in quoted strings using the format $'...', where a backslashed single quote can be used.
  • RM_STAR_SILENT, -H <K> <S> โ€” do not query the user before executing rm * or rm path/* ๐Ÿ’€. Living dangerously, we respect it.
  • RM_STAR_WAIT โ€” if you are being queried before executing rm * or rm path/*, first wait ten seconds and ignore anything typed in that time โณ. This avoids the problem of reflexively answering yes to the query when you didn't really mean it. Genuinely the most real problem ever. The wait and query can always be avoided by expanding the * in ZLE (with tab) ๐Ÿซถ.
  • SHORT_LOOPS <C> <Z> โ€” allow the short forms of for, repeat, select, if, and function constructs โœจ. Short and sweet.
  • SHORT_REPEAT โ€” allow the short form repeat as SHORT_LOOPS does, but without enabling it for the other constructs. Just the one. ๐ŸŽ€
  • SUN_KEYBOARD_HACK, -L โ€” if a line ends with a backquote, and there are an odd number of backquotes on the line, ignore the trailing backquote ๐Ÿ˜ญ. This is useful on some keyboards where the return key is too small, and the backquote key lies annoyingly close to it. Truly a hardware design crime. As an alternative, the variable KEYBOARD_HACK lets you choose the character to be removed ๐Ÿ’….

๐Ÿ‘‘ Job Control ๐Ÿ‘‘

  • AUTO_CONTINUE โ€” with this option set, stopped jobs that are removed from the job table with the disown builtin command are automatically sent a CONT signal to make them running ๐Ÿƒโ€โ™€๏ธ. Un-stopping them, basically.
  • AUTO_RESUME, -W โ€” treat single word simple commands without redirection as candidates for resumption of an existing job ๐Ÿ”.
  • BG_NICE, -6 <C> <Z> โ€” run all background jobs at a lower priority ๐Ÿ˜ด. This option is set by default.
  • CHECK_JOBS <Z> โ€” report the status of background and suspended jobs before exiting a shell with job control ๐Ÿ“‹; a second attempt to exit the shell will succeed. NO_CHECK_JOBS is best used only in combination with NO_HUP, else such jobs will be killed automatically. Yeah. Careful with that.

The check is omitted if the commands run from the previous command line included a jobs command, since it is assumed the user is aware that there are background or suspended jobs ๐Ÿ™ƒ. A jobs command run from one of the hook functions defined in the section SPECIAL FUNCTIONS in zshmisc(1) is not counted for this purpose.

  • CHECK_RUNNING_JOBS <Z> โ€” check for both running and suspended jobs when CHECK_JOBS is enabled โœจ. When this option is disabled, zsh checks only for suspended jobs, which matches the default behavior of bash. (Yes, we said the b-word.) This option has no effect unless CHECK_JOBS is set.
  • HUP <Z> โ€” send the HUP signal to running jobs when the shell exits ๐Ÿ‘‹. Bye bestie.
  • LONG_LIST_JOBS, -R โ€” print job notifications in the long format by default ๐Ÿ“œ.
  • MONITOR, -m, ksh: -m โ€” allow job control ๐ŸŽฎ. Set by default in interactive shells.
  • NOTIFY, -5, ksh: -b <Z> โ€” report the status of background jobs immediately, rather than waiting until just before printing a prompt โšก.
  • POSIX_JOBS <K> <S> โ€” this option makes job control more compliant with the POSIX standard ๐Ÿ“. Here's the breakdown:
    • When the option is not set, the MONITOR option is unset on entry to subshells, so that job control is no longer active.
    • When the option is set, the MONITOR option and job control remain active in the subshell โ€” but note that the subshell has no access to jobs in the parent shell. Slight L, but okay.
    • When the option is not set, jobs put in the background or foreground with bg or fg are displayed with the same information that would be reported by jobs.
    • When the option is set, only the text is printed.
    • The output from jobs itself is not affected by the option. Not even a little bit. ๐Ÿ’…

When the option's off, job info from the parent shell gets saved so it can be shown inside a subshell (pipeline vibes, yk). When it's on, jobs output is literally empty until you start a job inside that subshell. No cap.

Also, tiny history lesson ๐Ÿซถ โ€” in previous versions of the shell you had to enable POSIX_JOBS just for the builtin wait to return the status of background jobs that had already exited. That's no longer the case. We love growth.


๐ŸŒธ Prompting ๐ŸŒธ

  • PROMPT_BANG <K> โ€” if set, ! gets treated specially in prompt expansion. The receipts live in EXPANSION OF PROMPT SEQUENCES in zshmisc(1).
  • PROMPT_CR (+V) <D> โ€” prints a carriage return right before the prompt shows up in the line editor. It's on by default because multi-line editing is only possible if the editor knows where the start of the line is. Like, it needs that info, bestie.
  • PROMPT_SP <D> โ€” tries to preserve a partial line (i.e. a line that didn't end with a newline) that would otherwise get steamrolled by your command prompt thanks to PROMPT_CR. The way it works: it outputs some cursor-control characters, including a bunch of spaces, which should make the terminal wrap to the next line when a partial line is hanging around (note: this only works if your terminal has automatic margins, which is, like, typical ๐Ÿ’…).

When a partial line is preserved, by default you'll see an inverse+bold character at the end of it: a % for a normal user or a # for root. And if it's set, the shell parameter PROMPT_EOL_MARK can customize how the ends of partial lines are shown. Iconic.

NOTE: if the PROMPT_CR option is not set, enabling this option will have no effect. Also, this option is on by default.
  • PROMPT_PERCENT <C> <Z> โ€” if set, % gets treated specially in prompt expansion. Once again, see EXPANSION OF PROMPT SEQUENCES in zshmisc(1).
  • PROMPT_SUBST <K> <S> โ€” if set, parameter expansion, command substitution and arithmetic expansion all get performed in prompts. Substitutions inside prompts don't affect the command status, jsyk.
  • TRANSIENT_RPROMPT โ€” removes any right prompt from the display when you accept a command line. This may be useful with terminals that have other cut/paste methods ๐ŸŽ€.

๐Ÿงš Scripts and Functions ๐Ÿงš

  • ALIAS_FUNC_DEF <S> โ€” by default, zsh does not let you define functions with the name () syntax if name was expanded as an alias: that's an error. And honestly that's usually what you want, because otherwise an alias plus a function built on the same definition can very easily cause problems ๐Ÿ’€.

When this option is set, aliases can be used for defining functions.

For example, imagine these definitions as they might occur in a startup file:

alias foo=bar
foo() {
  print This probably does not do what you expect.
}

Here, foo gets expanded as an alias to bar before the () is even encountered, so the function defined would actually be named bar. By default this is instead an error in native mode. Note that quoting any part of the function name, or using the keyword function, avoids the problem โ€” so it's recommended when the function name can also be an alias.

  • C_BASES โ€” outputs hexadecimal numbers in the standard C format, like 0xFF instead of the usual 16#FF. If the option OCTAL_ZEROES is also set (it's not by default), octal numbers get treated similarly and hence appear as 077 instead of 8#77. This option has no effect on the choice of the output base, nor on the output of bases other than hexadecimal and octal. Note that these formats will be understood on input irrespective of the setting of C_BASES.
  • C_PRECEDENCES โ€” this alters the precedence of arithmetic operators to be more like C and other programming languages. The section ARITHMETIC EVALUATION in zshmisc(1) has an explicit list, so go peek ๐Ÿ‘€.
  • DEBUG_BEFORE_CMD <D> โ€” run the DEBUG trap before each command; otherwise it runs after each command. Setting this option mimics the behaviour of ksh 93; with the option unset, the behaviour is that of ksh 88.
  • ERR_EXIT (-e, ksh: -e) โ€” if a command has a non-zero exit status, execute the ZERR trap (if set) and exit. This is disabled while running initialization scripts.

The behaviour is also disabled inside DEBUG traps. In that case the option is handled specially: it is unset on entry to the trap. If the option DEBUG_BEFORE_CMD is set, as it is by default, and the option ERR_EXIT is found to have been set on exit, then the command for which the DEBUG trap is being executed is skipped. The option is restored after the trap exits.

A non-zero status in a command list containing && or || is ignored for commands that aren't at the end of the list. Hence

false && true

does not trigger exit.

Exiting due to ERR_EXIT has certain interactions with asynchronous jobs, noted in the section JOBS in zshmisc(1).

  • ERR_RETURN โ€” if a command has a non-zero exit status, return immediately from the enclosing function. The logic is similar to ERR_EXIT, except that an implicit return statement gets executed instead of an exit. This will trigger an exit at the outermost level of a non-interactive script.

Normally this option inherits the behaviour of ERR_EXIT that code followed by && || doesn't trigger a return. Hence in the following:

summit || true

no return is forced, since the combined effect always has a zero return status.

Note, however, that if summit in the example above is itself a function, code inside it is considered separately: it may force a return from summit (assuming the option remains set within summit), but not from the enclosing context. This behaviour is different from ERR_EXIT, which is unaffected by function scope. Sneaky but important ๐Ÿ™ˆ.

  • EVAL_LINENO <Z> โ€” if set, line numbers of expressions evaluated using the builtin eval are tracked separately from the enclosing environment. This applies both to the parameter LINENO and to the line number output by the prompt escape %i. If the option is set, the prompt escape %N will output the string (eval) instead of the script or function name, as an indication. (Those two prompt escapes are typically used in the parameter PS4 to be output when the option XTRACE is set.) If EVAL_LINENO is unset, the line number of the surrounding script or function is retained during the evaluation.
  • EXEC (+n, ksh: +n) <D> โ€” do execute commands. Without this option, commands are read and checked for syntax errors, but not executed. This option cannot be turned off in an interactive shell, except when -n is supplied to the shell at startup.
  • FUNCTION_ARGZERO <C> <Z> โ€” when executing a shell function or sourcing a script, set $0 temporarily to the name of the function/script. Note that toggling FUNCTION_ARGZERO from on to off (or off to on) does not change the current value of $0. Only the state upon entry to the function or script has an effect. Compare POSIX_ARGZERO.
  • LOCAL_LOOPS โ€” when this option is not set, the effect of break and continue commands may propagate outside function scope, affecting loops in calling functions ๐Ÿ˜ญ. When the option is set in a calling function, a break or a continue that isn't caught within a called function (regardless of the setting of the option within that function) produces a warning and the effect is cancelled.
  • LOCAL_OPTIONS <K> โ€” if this option is set at the point of return from a shell function, most options (including this one) which were in force upon entry to the function are restored; the options that are not restored are PRIVILEGED and RESTRICTED. Otherwise, only this option, and the LOCAL_LOOPS, XTRACE and PRINT_EXIT_VALUE options are restored. Hence if this is explicitly unset by a shell function, the other options in force at the point of return will remain so. A shell function can also guarantee itself a known shell configuration with a formulation like emulate -L zsh โ€” the -L activates LOCAL_OPTIONS.
  • LOCAL_PATTERNS โ€” if this option is set at the point of return from a shell function, the state of pattern disables (as set with the builtin command disable -p) is restored to what it was when the function was entered. The behaviour of this option is similar to the effect of LOCAL_OPTIONS on options; hence emulate -L sh (or indeed any other emulation with the -L option) activates LOCAL_PATTERNS.
  • LOCAL_TRAPS <K> โ€” if this option is set when a signal trap is set inside a function, then the previous status of the trap for that signal will be restored when the function exits. Note that this option must be set prior to altering the trap behaviour in a function; unlike LOCAL_OPTIONS, the value on exit from the function is irrelevant. However, it doesn't need to be set before any global trap for that to be correctly restored by a function. For example,
unsetopt localtraps
trap - INT
fn() { setopt localtraps; trap '' INT; sleep 3; }

will restore normal handling of SIGINT after the function exits. Chef's kiss ๐Ÿง‘โ€๐Ÿณ๐Ÿ’….

  • MULTI_FUNC_DEF <Z> โ€” allows definitions of multiple functions at once in the form fn1 fn2...(); if the option is not set, this causes a parse error. Definition of multiple functions with the function keyword is always allowed. Multiple function definitions aren't used very often and can cause obscure errors, so like... proceed with caution, bestie.
  • MULTIOS <Z> โ€” perform implicit tees or cats when multiple redirections are attempted (see the section Redirection).
  • OCTAL_ZEROES <S> โ€” interprets any integer constant beginning with a 0 as octal, per IEEE Std 1003.2-1992 (ISO 9945-2:1993). This is not enabled by default, since it causes problems with parsing of, for example, date and time strings with leading zeroes. so watch out ๐Ÿ˜ฌ

...and one last lil note on that whole numeric-base vibe: sequences of digits indicating a numeric base โ€” like the 08 bit in 08#77 โ€” are always read as decimal, no matter how many leading zeroes are sitting in front. Zero exceptions, no cap. ๐Ÿซถ

PIPE_FAIL

Okay so by default, when a pipeline finishes, the exit status that gets recorded by the shell and handed back to you in $? is the status of the rightmost element of that pipeline. That's just the vibe. But if you set PIPE_FAIL, the exit status instead reflects the status of the rightmost element of the pipeline that was non-zero โ€” or zero, if literally every element exited with zero status. Slay. โœจ

SOURCE_TRACE

Set this and zsh will print an informational message announcing the name of each file it loads. The format of the output is similar to the one you get with XTRACE, except the message is <sourcetrace>. A file can get loaded by the shell itself on startup and shutdown (see Startup/Shutdown Files), or by you using the source and dot builtin commands. It's giving โœจwatch me read my little filesโœจ and honestly? Obsessed.

TYPESET_SILENT

If this is unset, then running any of the typeset family of commands with no options and a list of parameters that already exist but have no values to assign will display the value of the parameter. If the option is set, they'll only be shown when parameters are selected with the -m option. The -p option is available whether or not the option is set โ€” that one's always there for you, bestie. ๐Ÿ’…

TYPESET_TO_UNSET <K> <S>

When you declare a new parameter with any of the typeset family of related commands, the parameter stays unset unless and until a value is explicitly assigned to it โ€” either right there in the typeset command itself, or later on in an assignment statement. No sneaky default values. Main character parameter energy only. ๐Ÿ‘‘

VERBOSE (-v, ksh: -v)

Print shell input lines as they're read. Cute, simple, does what it says.

XTRACE (-x, ksh: -x)

Print commands and their arguments as they get executed. The output is preceded by the value of $PS4, formatted the way the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1) describes.


๐ŸŒˆ Shell Emulation ๐ŸŒˆ

Welcome to the "pretend to be other shells" wing of the museum, bestie. ๐ŸŽ€

APPEND_CREATE <K> <S>

This option only applies when NO_CLOBBER (-C) is in effect. Important.

If this option is not set, the shell reports an error when an append redirection (>>) is used on a file that doesn't already exist โ€” that's the traditional zsh behaviour of NO_CLOBBER. If the option is set, no error is reported. That's the POSIX behaviour. Pick your fighter. ๐ŸฅŠ

BASH_REMATCH

When set, matches performed with the =~ operator will set the BASH_REMATCH array variable instead of the default MATCH and match variables. The first element of the BASH_REMATCH array holds the entire matched text, and the subsequent elements hold the extracted substrings.

This option makes way more sense when KSH_ARRAYS is also set, so that the entire matched portion lives at index 0 and the first substring is at index 1. Without this option, the MATCH variable contains the entire matched text and the match array variable contains the substrings. Iykyk. ๐Ÿฆ‹

BSD_ECHO <S>

Make the echo builtin compatible with the BSD echo(1) command. This disables backslashed escape sequences in echo strings unless the -e option is specified.

CONTINUE_ON_ERROR

If a fatal error is encountered (see the section ERRORS in zshmisc(1)) and the code is running in a script, the shell will resume execution at the next statement in the script at the top level โ€” in other words, outside all functions or shell constructs like loops and conditions.

This mimics how interactive shells behave, where the shell just returns to the line editor to read a new command. It was also the normal behaviour in versions of zsh before 5.0.1. Nostalgia trip. ๐Ÿ˜ญ

CSH_JUNKIE_HISTORY <C>

A history reference without an event specifier will always refer to the previous command. Without this option, such a history reference refers to the same event as the previous history reference on the current command line โ€” defaulting to the previous command.

CSH_JUNKIE_LOOPS <C>

Allow loop bodies to take the form list; end instead of do list; done. That's it. That's the whole option. csh girlies, this one's for you. ๐Ÿ’œ

CSH_JUNKIE_QUOTES <C>

Changes the rules for single- and double-quoted text to match csh's. These require that embedded newlines be preceded by a backslash โ€” unescaped newlines will cause an error message. In double-quoted strings, it becomes impossible to escape $, `, or " (and \ itself no longer needs escaping). Command substitutions are only expanded once, and cannot be nested.

CSH_NULLCMD <C>

Do not use the values of NULLCMD and READNULLCMD when running redirections with no command. This makes such redirections fail (see the section Redirection). Dramatic, but valid. ๐Ÿ’€

KSH_ARRAYS <K> <S>

Emulate ksh array handling as closely as possible. If this option is set:

  • array elements are numbered from zero
  • an array parameter without a subscript refers to the first element instead of the whole array
  • braces are required to delimit a subscript (${path[2]} rather than just $path[2]) or to apply modifiers to any parameter (${PWD:h} rather than $PWD:h)

KSH_AUTOLOAD <K> <S>

Emulate ksh function autoloading. This means that when a function is autoloaded, the corresponding file is merely executed, and it must define the function itself.

By default, the function is defined to the contents of the file. However, the most common ksh-style case โ€” where the file contains only a simple definition of the function โ€” is always handled in the ksh-compatible manner. Bestie, the shell is being nice to you. ๐Ÿซถ

KSH_OPTION_PRINT <K>

Alters the way option settings are printed: instead of separate lists of set and unset options, all options are shown, marked on if they're in the non-default state, and off otherwise. Full transparency, no secrets. โœจ

KSH_TYPESET

Heads up, this option is now obsolete: a better approximation to the behaviour of other shells is obtained with the reserved word interface to declare, export, float, integer, local, readonly and typeset. Note that the option is only applied when the reserved word interface is not in use.

Alters the way arguments to the typeset family of commands โ€” including declare, export, float, integer, local and readonly โ€” are processed. Without this option, zsh will perform normal word splitting after command and parameter expansion in the arguments of an assignment; with it, word splitting does not take place in those cases.

KSH_ZERO_SUBSCRIPT

Treat use of a subscript of value zero in array or string expressions as a reference to the first element โ€” i.e. the element that usually has the subscript 1. Ignored if KSH_ARRAYS is also set.

If neither this option nor KSH_ARRAYS is set, accesses to an element of an array or string with subscript zero return an empty element or string, while attempts to set element zero of an array or string are treated as an error. However, attempts to set an otherwise valid subscript range that includes zero will succeed. For example, if KSH_ZERO_SUBSCRIPT is not set,

array[0]=(element)

is an error, while

array[0,1]=(element)

is not โ€” and will replace the first element of the array.

This option is for compatibility with older versions of the shell and is not recommended in new code. Consider yourself warned, babe. ๐Ÿšจ

POSIX_ALIASES <K> <S>

When this option is set, reserved words are not candidates for alias expansion: it's still possible to declare any of them as an alias, but the alias will never be expanded. Reserved words are described in the section RESERVED WORDS in zshmisc(1).

Alias expansion takes place while text is being read; hence when this option is set it does not take effect until the end of any function or other piece of shell code parsed as one unit. Note this may cause differences from other shells even when the option is in effect. For example, when running a command with zsh -c, or even zsh -o posixaliases -c, the entire command argument is parsed as one unit, so aliases defined within the argument are not available even in later lines.

If in doubt, avoid use of aliases in non-interactive code. That's the whole tip. Do not fight it. ๐Ÿ’…

POSIX_ARGZERO

This option can be used to temporarily disable FUNCTION_ARGZERO and thereby restore the value of $0 to the name used to invoke the shell (or as set by the -c command line option).

For compatibility with previous versions of the shell, emulations use NO_FUNCTION_ARGZERO instead of POSIX_ARGZERO โ€” which may result in unexpected scoping of $0 if the emulation mode is changed inside a function or script. To avoid this, explicitly enable POSIX_ARGZERO in the emulate command:

emulate sh -o POSIX_ARGZERO

Note that NO_POSIX_ARGZERO has no effect unless FUNCTION_ARGZERO was already enabled upon entry to the function or script. Sneaky little ordering thing, but okay. ๐Ÿฆ‹

POSIX_BUILTINS <K> <S>

When this option is set, the command builtin can be used to execute shell builtin commands. Parameter assignments specified before shell functions and special builtins are kept after the command completes โ€” unless the special builtin is prefixed with the command builtin.

The special builtins, for the record, are: ., :, break, continue, declare, eval, exit, export, integer, local, readonly, return, set, shift, source, times, trap and unset.

In addition, various error conditions associated with the above builtins or with exec cause a non-interactive shell to exit, and an interactive shell to return to its top-level processing. So basically: behave, or get sent to the top level. ๐Ÿ˜ญ

Furthermore, functions and shell builtins are not executed after an exec prefix; the command to be executed must be an external command found in the path.

Furthermore, the getopts builtin behaves in a POSIX-compatible fashion, in that the associated variable OPTIND is not made local to functions, and its value is calculated differently to match other shells.

Moreover, the warning and special exit code from [[ -o non_existent_option ]] are suppressed. Quietly iconic. ๐Ÿคซ

POSIX_IDENTIFIERS <K> <S>

When this option is set, only the ASCII characters a to z, A to Z, 0 to 9 and _ may be used in identifiers (names of shell parameters and modules). ASCII only, bestie โ€” no exotic glyphs in your variable names. ๐ŸŽ€

Setting this option also puts a lil leash on parameter substitution when you skip the braces, bestie. So $# is treated as the parameter $# even if a valid parameter name is right after it. With the option unset, zsh lets expressions like $#name mean โ€œthe length of $nameโ€ โ€” even for special variables, so $#- and $#* are a whole thing.

Another difference: with the option set, assigning to an unset variable in arithmetic context makes that variable a scalar instead of a numeric type. So after unset t; (( t = 3 )), if POSIX_IDENTIFIERS is not set, t has integer type; if it is set, t has scalar type.

When the option is unset and multibyte character support is enabled โ€” meaning itโ€™s compiled in and the MULTIBYTE option is set โ€” then any alphanumeric characters in the local character set may also be used in identifiers.

โš ๏ธ Scripts and functions written with this feature are not portable, and both options must be set before the script or function is parsed. Setting them during execution is not enough, because variable=value has already been parsed as a command instead of an assignment.

If multibyte character support is not compiled into the shell, this option is ignored; all octets with the top bit set may be used in identifiers. Thatโ€™s non-standard, but itโ€™s the traditional zsh behaviour. iykyk ๐Ÿ’…

  • POSIX_STRINGS <K> <S> โ€” This one affects how quoted strings get processed. Currently it only touches the behaviour of null characters โ€” thatโ€™s character 0 in the portable character set corresponding to US ASCII.

When this option is not set, null characters embedded inside strings of the form $'...' are treated as ordinary characters. The entire string is maintained within the shell and output to files where necessary, although owing to restrictions of the library interface the string is truncated at the null character in file names, environment variables, or in arguments to external programs.

When this option is set, the $'...' expression is truncated at the null character. Heads up: the remaining parts of the same string beyond the termination of the quotes are not truncated.

Example time: the command line argument a$'b\0c'd is treated with the option off as the characters a, b, null, c, d, and with the option on as the characters a, b, d. ๐Ÿ“

  • POSIX_TRAPS <K> <S> โ€” With this set, the usual zsh behaviour of executing traps for EXIT on exit from shell functions is suppressed. In that case, manipulating EXIT traps always alters the global trap for exiting the shell; the LOCAL_TRAPS option is ignored for the EXIT trap.

Also, a return statement executed in a trap with no argument passes back from the function the value from the surrounding context, not from code executed within the trap.

Furthermore, if a trap is set to be ignored, this state persists when a subshell is entered. Without the option, the trap would be reset to its default state at this point.

  • SH_FILE_EXPANSION <K> <S> โ€” Performs filename expansion (e.g., ~ expansion) before parameter expansion, command substitution, arithmetic expansion and brace expansion. If this option is unset, it is performed after brace expansion, so things like ~$USERNAME and ~{pfalstad,rc} will work. Obsessed with a brace-expansion moment, ngl. โœจ
  • SH_NULLCMD <K> <S> โ€” Do not use the values of NULLCMD and READNULLCMD when doing redirections; use : instead (see the section Redirection).
  • SH_OPTION_LETTERS <K> <S> โ€” If this option is set, the shell tries to interpret single letter options (which are used with set and setopt) like ksh does. This also affects the value of the - special parameter.
  • SH_WORD_SPLIT (-y) <K> <S> โ€” Causes field splitting to be performed on unquoted parameter expansions. Note that this option has nothing to do with word splitting. (See zshexpn(1).)
  • TRAPS_ASYNC โ€” While waiting for a program to exit, handle signals and run traps immediately. Otherwise the trap is run after a child process has exited. Note this does not affect the point at which traps are run for any case other than when the shell is waiting for a child process.

๐Ÿ’ป Shell State ๐Ÿ’ป

  • INTERACTIVE (-i, ksh: -i) โ€” This is an interactive shell. This option is set upon initialisation if the standard input is a tty and commands are being read from standard input. (See the discussion of SHIN_STDIN.) This heuristic may be overridden by specifying a state for this option on the command line. The value of this option can only be changed via flags supplied at invocation of the shell. It cannot be changed once zsh is running.
  • LOGIN (-l, ksh: -l) โ€” This is a login shell. If this option is not explicitly set, the shell becomes a login shell if the first character of the argv[0] passed to the shell is a -.
  • PRIVILEGED (-p, ksh: -p) โ€” Turns on privileged mode. Typically this is used when a script is to be run with elevated privileges. This should be done as follows directly with the -p option to zsh so that it takes effect during startup.
#!/bin/zsh -p

The option is enabled automatically on startup if the effective user (group) ID is not equal to the real user (group) ID. In this case, turning the option off causes the effective user and group IDs to be set to the real user and group IDs. Be aware that if that fails the shell may be running with different IDs than was intended, so a script should check for failure and act accordingly, for example:

unsetopt privileged || exit

The PRIVILEGED option disables sourcing user startup files. If zsh is invoked as sh or ksh with this option set, /etc/suid_profile is sourced (after /etc/profile on interactive shells). Sourcing ~/.profile is disabled and the contents of the ENV variable is ignored. This option cannot be changed using the -m option of setopt and unsetopt, and changing it inside a function always changes it globally regardless of the LOCAL_OPTIONS option. ๐Ÿ‘‘

  • RESTRICTED (-r) โ€” Enables restricted mode. This option cannot be changed using unsetopt, and setting it inside a function always changes it globally regardless of the LOCAL_OPTIONS option. See the section Restricted Shell.
  • SHIN_STDIN (-s, ksh: -s) โ€” Commands are being read from the standard input. Commands are read from standard input if no command is specified with -c and no file of commands is specified. If SHIN_STDIN is set explicitly on the command line, any argument that would otherwise have been taken as a file to run will instead be treated as a normal positional parameter. Note that setting or unsetting this option on the command line does not necessarily affect the state the option will have while the shell is running โ€” that is purely an indicator of whether or not commands are actually being read from standard input. The value of this option can only be changed via flags supplied at invocation of the shell. It cannot be changed once zsh is running.
  • SINGLE_COMMAND (-t, ksh: -t) โ€” If the shell is reading from standard input, it exits after a single command has been executed. This also makes the shell non-interactive, unless the INTERACTIVE option is explicitly set on the command line. The value of this option can only be changed via flags supplied at invocation of the shell. It cannot be changed once zsh is running.

โŒจ๏ธ Zle โŒจ๏ธ

  • BEEP (+B) <D> โ€” Beep on error in ZLE.
  • COMBINING_CHARS โ€” Assumes that the terminal displays combining characters correctly. Specifically, if a base alphanumeric character is followed by one or more zero-width punctuation characters, assume that the zero-width characters will be displayed as modifications to the base character within the same width. Not all terminals handle this. If this option is not set, zero-width characters are displayed separately with special mark-up.

If this option is set, the pattern test [[:WORD:]] matches a zero-width punctuation character on the assumption that it will be used as part of a word in combination with a word character. Otherwise the base shell does not handle combining characters specially.

  • EMACS โ€” If ZLE is loaded, turning on this option has the equivalent effect of bindkey -e. In addition, the VI option is unset. Turning it off has no effect. The option setting is not guaranteed to reflect the current keymap. This option is provided for compatibility; bindkey is the recommended interface.
  • OVERSTRIKE โ€” Start up the line editor in overstrike mode.
  • SINGLE_LINE_ZLE (-M) <K> โ€” Use single-line command line editing instead of multi-line.

Note that although this is on by default in ksh emulation it only provides superficial compatibility with the ksh line editor and reduces the effectiveness of the zsh line editor. As it has no effect on shell syntax, many users may wish to disable this option when using ksh emulation interactively. ๐Ÿซถ

  • VI โ€” If ZLE is loaded, turning on this option has the equivalent effect of bindkey -v. In addition, the EMACS option is unset. Turning it off has no effect. The option setting is not guaranteed to reflect the current keymap. This option is provided for compatibility; bindkey is the recommended interface.
  • ZLE (-Z) โ€” Use the zsh line editor. Set by default in interactive shells connected to a terminal.

โœจ OPTION ALIASES โœจ

ok so a handful of options are out here living double lives ๐Ÿ’… some of them have alternative names, and here's the tea: these aliases are never used for output โ€” like, they will not show up when the shell tells you what's set โ€” but bestie you can still use them exactly like normal option names whenever you're specifying options to the shell. no cap ๐Ÿซถ

  • BRACE_EXPAND โ€” alias for NO_IGNORE_BRACES (ksh and bash compatibility)
  • DOT_GLOB โ€” alias for GLOB_DOTS (bash compatibility)
  • HASH_ALL โ€” alias for HASH_CMDS (bash compatibility)
  • HIST_APPEND โ€” alias for APPEND_HISTORY (bash compatibility)
  • HIST_EXPAND โ€” alias for BANG_HIST (bash compatibility)
  • LOG โ€” alias for NO_HIST_NO_FUNCTIONS (ksh compatibility)
  • MAIL_WARN โ€” alias for MAIL_WARNING (bash compatibility)
  • ONE_CMD โ€” alias for SINGLE_COMMAND (bash compatibility)
  • PHYSICAL โ€” alias for CHASE_LINKS (ksh and bash compatibility)
  • PROMPT_VARS โ€” alias for PROMPT_SUBST (bash compatibility)
  • STDIN โ€” alias for SHIN_STDIN (ksh compatibility)
  • TRACK_ALL โ€” alias for HASH_CMDS (ksh compatibility)

๐ŸŽ€ SINGLE LETTER OPTIONS ๐ŸŽ€

yes, the shell really does accept one-letter shortcuts for a whole bunch of options ๐Ÿ˜ญ it's giving vintage, it's giving "my fingers are tired", and honestly? iconic. here's the full map, no skipping, no summarizing, we're doing all of it ๐ŸŒธ

Default set

this is the lineup you get by default, letter by letter ๐Ÿฆ‹

  • -0 โ€” CORRECT
  • -1 โ€” PRINT_EXIT_VALUE
  • -2 โ€” NO_BAD_PATTERN
  • -3 โ€” NO_NOMATCH
  • -4 โ€” GLOB_DOTS
  • -5 โ€” NOTIFY
  • -6 โ€” BG_NICE
  • -7 โ€” IGNORE_EOF
  • -8 โ€” MARK_DIRS
  • -9 โ€” AUTO_LIST
  • -B โ€” NO_BEEP
  • -C โ€” NO_CLOBBER
  • -D โ€” PUSHD_TO_HOME
  • -E โ€” PUSHD_SILENT
  • -F โ€” NO_GLOB
  • -G โ€” NULL_GLOB
  • -H โ€” RM_STAR_SILENT
  • -I โ€” IGNORE_BRACES
  • -J โ€” AUTO_CD
  • -K โ€” NO_BANG_HIST
  • -L โ€” SUN_KEYBOARD_HACK
  • -M โ€” SINGLE_LINE_ZLE
  • -N โ€” AUTO_PUSHD
  • -O โ€” CORRECT_ALL
  • -P โ€” RC_EXPAND_PARAM
  • -Q โ€” PATH_DIRS
  • -R โ€” LONG_LIST_JOBS
  • -S โ€” REC_EXACT
  • -T โ€” CDABLE_VARS
  • -U โ€” MAIL_WARNING
  • -V โ€” NO_PROMPT_CR
  • -W โ€” AUTO_RESUME
  • -X โ€” LIST_TYPES
  • -Y โ€” MENU_COMPLETE
  • -Z โ€” ZLE
  • -a โ€” ALL_EXPORT
  • -e โ€” ERR_EXIT
  • -f โ€” NO_RCS
  • -g โ€” HIST_IGNORE_SPACE
  • -h โ€” HIST_IGNORE_DUPS
  • -i โ€” INTERACTIVE
  • -k โ€” INTERACTIVE_COMMENTS
  • -l โ€” LOGIN
  • -m โ€” MONITOR
  • -n โ€” NO_EXEC
  • -p โ€” PRIVILEGED
  • -r โ€” RESTRICTED
  • -s โ€” SHIN_STDIN
  • -t โ€” SINGLE_COMMAND
  • -u โ€” NO_UNSET
  • -v โ€” VERBOSE
  • -w โ€” CHASE_LINKS
  • -x โ€” XTRACE
  • -y โ€” SH_WORD_SPLIT

sh/ksh emulation set

when you're in sh/ksh emulation mode the letters get remapped a lil bit ๐Ÿ‘€ same energy, different assignments:

  • -C โ€” NO_CLOBBER
  • -T โ€” TRAPS_ASYNC
  • -X โ€” MARK_DIRS
  • -a โ€” ALL_EXPORT
  • -b โ€” NOTIFY
  • -e โ€” ERR_EXIT
  • -f โ€” NO_GLOB
  • -i โ€” INTERACTIVE
  • -l โ€” LOGIN
  • -m โ€” MONITOR
  • -n โ€” NO_EXEC
  • -p โ€” PRIVILEGED
  • -r โ€” RESTRICTED
  • -s โ€” SHIN_STDIN
  • -t โ€” SINGLE_COMMAND
  • -u โ€” NO_UNSET
  • -v โ€” VERBOSE
  • -x โ€” XTRACE

Also note

and these ones? they're not "set the option" letters at all, they mean something else depending on where you use them ๐Ÿ™ˆ read carefully bestie:

  • -A โ€” used by set for setting arrays
  • -b โ€” used on the command line to specify end of option processing
  • -c โ€” used on the command line to specify a single command
  • -m โ€” used by setopt for pattern-matching option setting
  • -o โ€” used in all places to allow use of long option names
  • -s โ€” used by set to sort positional parameters

๐Ÿ’€ quick vibe check: yeah -m shows up in the emulation set and in "also note" meaning two completely different things, and -b/-s pull double duty too. that's not a typo, that's just how it is. don't come for me, come for the manual ๐Ÿ˜Œ

and that's a wrap on the whole page, bestie!! ๐ŸŽ‰ you made it to the very end โ€” genuinely proud of you ๐Ÿซถ this edition is zsh 5.9.2, dated July 12, 2026, and it's been an absolute honour yapping about options with you. go forth and configure responsibly โœจ๐Ÿ’œ๐Ÿ‘‘

๐Ÿ“ฆ where this page comes from