ZSHBUILTINS(1)

๐Ÿ’– NAME ๐Ÿ’–

zshbuiltins โ€” zsh built-in commands. Yep bestie, this is the zshbuiltins(1) page, and it is literally the whole built-in command squad. slay ๐Ÿ’…โœจ

๐ŸŒธ SHELL BUILTIN COMMANDS ๐ŸŒธ

Okay so first, the vibe check on how options work around here. Some shell builtin commands take options as described in individual entries; these are often referred to in the list below as flags to avoid confusion with shell options, which may also have an effect on the behaviour of builtin commands. In this introductory section, option always has the meaning of an option to a command that should be familiar to most command line users.

Typically, options are single letters preceded by a hyphen (-). Options that take an argument accept it either immediately following the option letter or after white space, for example print -C3 {1..9} or print -C 3 {1..9} are equivalent. Arguments to options are not the same as arguments to the command; the documentation indicates which is which. Options that do not take an argument may be combined in a single word, for example print -rca -- * and print -r -c -a -- * are equivalent.

Some shell builtin commands also take options that begin with + instead of -. The list below makes clear which commands these are.

Options (together with their individual arguments, if any) must appear in a group before any non-option arguments; once the first non-option argument has been found, option processing is terminated.

All builtin commands other than echo and precommand modifiers, even those that have no options, can be given the argument -- to terminate option processing. This indicates that the following words are non-option arguments, but is otherwise ignored. This is useful in cases where arguments to the command may begin with -. For historical reasons, most builtin commands (including echo) also recognize a single - in a separate word for this purpose; note that this is less standard and use of -- is recommended.

๐Ÿ’… tiny but iconic note: -- is the recommended โ€œstop reading optionsโ€ signal. periodt.

โœจ - simple command โœจ

See the section Precommand Modifiers in zshmisc(1).

๐Ÿฆ‹ . file [ arg ... ] ๐Ÿฆ‹

. file [ arg ... ]

Read commands from file and execute them in the current shell environment.

If file does not contain a slash, or if PATH_DIRS is set, the shell looks in the components of $path to find the directory containing file. Files in the current directory are not read unless . appears somewhere in $path. If a file named file.zwc is found, is newer than file, and is the compiled form (created with the zcompile builtin) of file, then commands are read from that file instead of file.

If any arguments arg are given, they become the positional parameters; the old positional parameters are restored when the file is done executing. However, if no arguments are given, the positional parameters remain those of the calling context, and no restoring is done.

If file was not found the return status is 127; if file was found but contained a syntax error the return status is 126; else the return status is the exit status of the last command executed.

๐ŸŽ€ : [ arg ... ] ๐ŸŽ€

: [ arg ... ]

This command does nothing, although normal argument expansions is performed which may have effects on shell parameters. A zero exit status is returned.

๐Ÿ’œ alias ๐Ÿ’œ

alias [ {+|-}gmrsL ] [ name[=value] ... ]

For each name with a corresponding value, define an alias with that value. A trailing space in value causes the next word to be checked for alias expansion. If the -g flag is present, define a global alias; global aliases are expanded even if they do not occur in command position:

% perldoc --help 2>&1 | grep 'built-in functions'
    -f   Search Perl built-in functions
% alias -g HG='--help 2>&1 | grep'
% perldoc HG 'built-in functions'
    -f   Search Perl built-in functions

If the -s flag is present, define a suffix alias: if the command word on a command line is in the form text.name, where text is any non-empty string, it is replaced by the text value text.name. Note that name is treated as a literal string, not a pattern. A trailing space in value is not special in this case. For example,

alias -s ps='gv --'

will cause the command *.ps to be expanded to gv -- *.ps. As alias expansion is carried out earlier than globbing, the *.ps will then be expanded. Suffix aliases constitute a different name space from other aliases (so in the above example it is still possible to create an alias for the command ps) and the two sets are never listed together.

For each name with no value, print the value of name, if any. With no arguments, print all currently defined aliases other than suffix aliases. If the -m flag is given the arguments are taken as patterns (they should be quoted to preserve them from being interpreted as glob patterns), and the aliases matching these patterns are printed. When printing aliases and one of the -g, -r or -s flags is present, restrict the printing to global, regular or suffix aliases, respectively; a regular alias is one which is neither a global nor a suffix alias. Using + instead of -, or ending the option list with a single +, prevents the values of the aliases from being printed.

If the -L flag is present, then print each alias in a manner suitable for putting in a startup script. The exit status is nonzero if a name (with no value) is given for which no alias has been defined.

For more on aliases, include common problems, see the section ALIASING in zshmisc(1).

๐ŸŒˆ autoload ๐ŸŒˆ

autoload [ {+|-}RTUXdkmrtWz ] [ -w ] [ name ... ]

See the section Autoloading Functions in zshmisc(1) for full details. The fpath parameter will be searched to find the function definition when the function is first referenced.

If name consists of an absolute path, the function is defined to load from the file given (searching as usual for dump files in the given location). The name of the function is the basename (non-directory part) of the file. It is normally an error if the function is not found in the given location; however, if the option -d is given, searching for the function defaults to $fpath. If a function is loaded by absolute path, any functions loaded from it that are marked for autoload without an absolute path have the load path of the parent function temporarily prepended to $fpath.

If the option -r or -R is given, the function is searched for immediately and the location is recorded internally for use when the function is executed; a relative path is expanded using the value of $PWD. This protects against a change to $fpath after the call to autoload. With -r, if the function is not found, it is silently left unresolved until execution; with -R, an error message is printed and command processing aborted immediately the search fails, i.e. at the autoload command rather than at function execution..

The flag -X may be used only inside a shell function. It causes the calling function to be marked for autoloading and then immediately loaded and executed, with the current array of positional parameters as arguments. This replaces the previous definition of the function. If no function definition is found, an error is printed and the function remains undefined and marked for autoloading. If an argument is given, it is used as a directory (i.e. it does not include the name of the function) in which the function is to be found; this may be combined with the -d option to allow the function search to default to $fpath if it is not in the given location.

The flag +X attempts to load each name as an autoloaded function, but does not execute it. The exit status is zero (success) if the function was not previously defined and a definition for it was found. This does not replace any existing definition of the function. The exit status is nonzero (failure) if the function was already defined or when no definition was found. In the latter case the function remains undefined and marked for autoloading. If ksh-style autoloading is enabled, the function created will contain the contents of the file plus a call to the function itself appended to it, thus giving normal ksh autoloading behaviour on the first call to the function. If the -m flag is also given each name is treated as a pattern and all functions already marked for autoload that match the pattern are loaded.

With the -t flag, turn on execution tracing; with -T, turn on execution tracing only for the current function, turning it off on entry to any called functions that do not also have tracing enabled.

With the -U flag, alias expansion is suppressed when the function is loaded.

With the -w flag, the names are taken as names of files compiled with the zcompile builtin, and all functions defined in them are marked for autoloading.

The flags -z and -k mark the function to be autoloaded using the zsh or ksh style, as if the option KSH_AUTOLOAD were unset or were set, respectively. The flags override the setting of the option at the time the function is loaded.

Note that the autoload command makes no attempt to ensure the shell options set during the loading or execution of the file have any particular value. For this, the emulate command can be used:

emulate zsh -c 'autoload -Uz func'

arranges that when func is loaded the shell is in native zsh emulation, and this emulation is also applied when func is run.

Some of the functions of autoload are also provided by functions -u or functions -U, but autoload is a more comprehensive interface.

๐Ÿซถ bg [ job ... ] + job ... & ๐Ÿซถ

bg [ job ... ]
job ... &

Put each specified job in the background, or the current job if none is specified.

โญ bindkey โญ

See the section Zle Builtins in zshzle(1).

๐Ÿ”ฅ break [ n ] ๐Ÿ”ฅ

break [ n ]

Exit from an enclosing for, while, until, select or repeat loop. If an arithmetic expression n is specified, then break n levels instead of just one.

๐Ÿ‘‘ builtin name [ args ... ] ๐Ÿ‘‘

builtin name [ args ... ]

Executes the builtin name, with the given args.

๐ŸŒธ bye ๐ŸŒธ

Same as exit.

๐Ÿš cap

See the section The zsh/cap Module'</cyan> in zshmodules(1)`. bestie it's giving "go read the module page", iykyk โœจ


๐Ÿ“ cd

cd [ -qsLP ] [ arg ]
cd [ -qsLP ] old new
cd [ -qsLP ] {+|-}n

Okay so this is the "take me somewhere else" builtin, and she has layers ๐Ÿ’…

Form one: change the current directory to arg, or to the value of $HOME if arg isn't specified. If arg is -, you go to the previous directory. Iconic little shortcut, no cap ๐ŸŽ€

Otherwise, if arg begins with a slash, just try to change to the directory given by arg. Simple.

If arg does not begin with a slash, the behaviour depends on whether the current directory . occurs in the list of directories contained in the shell parameter cdpath:

  • If . does not occur there: first attempt to change to the directory arg under the current directory, and if that fails but cdpath is set and contains at least one element, attempt to change to the directory arg under each component of cdpath in turn until successful.
  • If . does occur in cdpath, then cdpath is searched strictly in order so that . is only tried at the appropriate point.

The order of testing cdpath is modified if the option POSIX_CD is set, as described in the documentation for the option ๐Ÿ‘‘

If no directory is found, the option CDABLE_VARS is set, and a parameter named arg exists whose value begins with a slash, treat its value as the directory. In that case, the parameter is added to the named directory hash table. slay, variable-powered navigation ๐ŸŒˆ

Form two: cd substitutes the string new for the string old in the name of the current directory, and tries to change to this new directory. Find-and-replace but make it a location ๐Ÿฆ‹

Form three: cd extracts an entry from the directory stack and changes to that directory.

  • An argument of the form +n identifies a stack entry by counting from the left of the list shown by the dirs command, starting with zero.
  • An argument of the form -n counts from the right.
  • If the PUSHD_MINUS option is set, the meanings of + and - in this context are swapped ๐Ÿ™ƒ
  • If the POSIX_CD option is set, this form of cd is not recognised and will be interpreted as the first form. periodt.
Heads up: if the -q (quiet) option is specified, the hook function chpwd and the functions in the array chpwd_functions are not called. This is useful for calls to cd that do not change the environment seen by an interactive user ๐Ÿ’–
  • -s โ€” cd refuses to change the current directory if the given pathname contains symlinks.
  • -P โ€” symbolic links are resolved to their true values. (Also happens if the CHASE_LINKS option is set.)
  • -L โ€” symbolic links are retained in the directory (and not resolved) regardless of the state of the CHASE_LINKS option.

๐Ÿ” chdir

Same as cd. literally the same girl, different name ๐Ÿ’ซ


๐Ÿงฌ clone

See the section The zsh/clone Module'</cyan> in zshmodules(1)`.


โšก command

command [ -pvV ] simple command

The simple command argument is taken as an external command instead of a function or builtin, and is executed. If the POSIX_BUILTINS option is set, builtins will also be executed but certain special properties of them are suppressed. Spooky. ๐Ÿ‘€

  • -p โ€” causes a default path to be searched instead of that in $path.
  • -v โ€” command is similar to whence.
  • -V โ€” equivalent to whence -v.

See also the section Precommand Modifiers'</cyan> in zshmisc(1)` โœจ


๐Ÿงฉ comparguments

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compcall

See the section The zsh/compctl Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compctl

See the section The zsh/compctl Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compdescribe

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compfiles

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compgroups

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compquote

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ comptags

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ comptry

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.

๐Ÿงฉ compvalues

See the section The zsh/computil Module'</cyan> in zshmodules(1)`.


โญ๏ธ continue

continue [ n ]

Resume the next iteration of the enclosing for, while, until, select or repeat loop. If an arithmetic expression n is specified, break out of n-1 loops and resume at the *n*th enclosing loop. it's giving "skip ahead but make it math" ๐Ÿฆ‹


๐Ÿ“ declare

Same as typeset. twin energy ๐Ÿ’œ


๐Ÿ—‚๏ธ dirs

dirs [ -c ] [ arg ... ]
dirs [ -lpv ]

With no arguments, print the contents of the directory stack. Directories are added to this stack with the pushd command, and removed with the cd or popd commands. If arguments are specified, load them onto the directory stack, replacing anything that was there, and push the current directory onto the stack. out with the old, in with the new โœจ

  • -c โ€” clear the directory stack.
  • -l โ€” print directory names in full instead of using ~ expressions (see Dynamic and Static named directories in zshexpn(1)).
  • -p โ€” print directory entries one per line.
  • -v โ€” number the directories in the stack when printing.

๐Ÿšซ disable

disable [ -afmprs ] name ...

Temporarily disable the named hash table elements or patterns. The default is to disable builtin commands โ€” which is lowkey the whole point: it lets you use an external command with the same name as a builtin command ๐Ÿ’…

  • -a โ€” act on regular or global aliases.
  • -s โ€” act on suffix aliases.
  • -f โ€” act on shell functions.
  • -r โ€” act on reserved words.

Without arguments, all disabled hash table elements from the corresponding hash table are printed. With the -m flag the arguments are taken as patterns (which should be quoted to prevent them from undergoing filename expansion), and all hash table elements from the corresponding hash table matching these patterns are disabled. Disabled objects can be enabled with the enable command ๐Ÿซถ

With the option -p, name ... refer to elements of the shell's pattern syntax as described in the section `Filename Generation'. Certain elements can be disabled separately, as given below.

โš ๏ธ Note that patterns not allowed by the current settings for the options EXTENDED_GLOB, KSH_GLOB and SH_GLOB are never enabled, regardless of the setting here. For example, if EXTENDED_GLOB is not active, the pattern ^ is ineffective even if disable -p "^" has not been issued. The list below indicates any option settings that restrict the use of the pattern. It should be noted that setting SH_GLOB has a wider effect than merely disabling patterns, as certain expressions โ€” in particular those involving parentheses โ€” are parsed differently. not me dropping lore on you but this matters fr fr ๐Ÿ˜ญ

The following patterns may be disabled; all the strings need quoting on the command line to prevent them from being interpreted immediately as patterns, and the patterns are shown below in single quotes as a reminder ๐ŸŽ€

  • '?' โ€” the pattern character ? wherever it occurs, including when preceding a parenthesis with KSH_GLOB.
  • '*' โ€” the pattern character * wherever it occurs, including recursive globbing and when preceding a parenthesis with KSH_GLOB.
  • '[' โ€” character classes.
  • '<' (NO_SH_GLOB) โ€” numeric ranges.
  • '|' (NO_SH_GLOB) โ€” alternation in grouped patterns, case statements, or KSH_GLOB parenthesised expressions.
  • '(' (NO_SH_GLOB) โ€” grouping using single parentheses. Disabling this does not disable the use of parentheses for KSH_GLOB where they are introduced by a special character, nor for glob qualifiers (use setopt NO_BARE_GLOB_QUAL to disable glob qualifiers that use parentheses only).
  • '~' (EXTENDED_GLOB) โ€” exclusion in the form A~B.
  • '^' (EXTENDED_GLOB) โ€” exclusion in the form A^B.
  • '#' (EXTENDED_GLOB) โ€” the pattern character # wherever it occurs, both for repetition of a previous pattern and for indicating globbing flags.
  • '?(' (KSH_GLOB) โ€” the grouping form ?(...). Note this is also disabled if '?' is disabled.
  • '*(' (KSH_GLOB) โ€” the grouping form *(...). Note this is also disabled if '*' is disabled.
  • '+(' (KSH_GLOB) โ€” the grouping form +(...).
  • '!(' (KSH_GLOB) โ€” the grouping form !(...).
  • '@(' (KSH_GLOB) โ€” the grouping form @(...).

๐Ÿ‘‹ disown

disown [ job ... ]
job ... &|
job ... &!

Remove the specified jobs from the job table; the shell will no longer report their status, and will not complain if you try to exit an interactive shell with them running or stopped. If no job is specified, disown the current job. it's giving "you're dead to me but in a respectful way" ๐Ÿ’€

If the jobs are currently stopped and the AUTO_CONTINUE option is not set, a warning is printed containing information about how to make them running after they have been disowned. If one of the latter two forms is used, the jobs will automatically be made running, independent of the setting of the AUTO_CONTINUE option. slay, forced cardio ๐Ÿ”ฅ


๐Ÿ“ข echo

echo [ -neE ] [ arg ... ]

Write each arg on the standard output, with a space separating each one. If the -n flag is not present, print a newline at the end. The people's favourite, no cap ๐Ÿ’–

echo recognizes the following escape sequences:

  • \a โ€” bell character
  • \b โ€” backspace
  • \c โ€” suppress subsequent characters and final newline
  • \e โ€” escape
  • \f โ€” form feed
  • \n โ€” linefeed (newline)
  • \r โ€” carriage return
  • \t โ€” horizontal tab
  • \v โ€” vertical tab
  • \\ โ€” backslash
  • \0NNN โ€” character code in octal
  • \xNN โ€” character code in hexadecimal
  • \uNNNN โ€” unicode character code in hexadecimal
  • \UNNNNNNNN โ€” unicode character code in hexadecimal

The -E flag, or the BSD_ECHO option, can be used to disable these escape sequences. In the latter case, the -e flag can be used to enable them ๐ŸŒธ

Quick note before we keep going, bestie: for standards compliance, a double dash does not terminate option processing โ€” it just gets printed straight up. But a single dash does kill option processing, so the first dash (possibly after some options) never gets printed, and everything after it prints as an argument. Heads up: that single-dash behaviour is different from other shells. If you want a more portable way of printing text, go peep printf, and for a more controllable way of printing text inside zsh, go peep print. ๐Ÿ’…

  • echotc โ€” see the section The zsh/termcap Module in zshmodules(1). โœจ
  • echoti โ€” see the section The zsh/terminfo Module in zshmodules(1). โœจ

๐Ÿฆ‹ emulate [ -lLR ] [ {zsh|sh|ksh|csh} [ flags ... ] ]

Okay so with zero arguments, it just prints the current emulation mode. That's it. Vibe check only.

With a single argument, it sets up zsh options to emulate that shell as much as possible. And like, csh will never be fully emulated โ€” that's just the truth, no cap. If the argument isn't one of the shells listed above, zsh gets used as the default; more precisely, the tests it runs on the argument are the same ones used to figure out emulation at startup based on the shell name โ€” see the section COMPATIBILITY in zsh(1). Besides setting shell options, the command also restores the pristine state of pattern enables, as if all patterns had been enabled using enable -p. Iconic little bonus. ๐ŸŽ€

If emulate happens inside a function that's been marked for execution tracing with functions -t, then the xtrace option gets turned on regardless of emulation mode or any other options. But โ€” and this is the sneaky part โ€” code executed inside the function by the ., source, or eval commands is not considered to be running directly from the function, so it doesn't provoke this behaviour. ๐Ÿ™ˆ

If you give the -R switch, all settable options get reset to their default value for that emulation mode, except for certain options describing the interactive environment. Otherwise? Only the options likely to cause portability problems in scripts and functions get altered. If you give the -L switch, the options LOCAL_OPTIONS, LOCAL_PATTERNS and LOCAL_TRAPS get set as well โ€” which makes the effects of the emulate command, plus any setopt, disable -p or enable -p, and trap commands, local to the immediately surrounding shell function (if there is one). Normally these options are turned off in all emulation modes except ksh. Oh and -L is mutually exclusive with using -c in flags.

If there's a single argument and you throw in the -l switch, it lists the options that would be set or unset (unsets get the prefix no in front). You can combine -l with -L or -R and the list gets modified the appropriate way. Note: the list does not depend on the current setting of options โ€” it includes everything that could in principle change, not just the stuff that would actually change. ๐Ÿ’€

The flags can be any of the invocation-time flags described in the section INVOCATION in zsh(1), except that -o EMACS and -o VI may not be used. And flags like +r/+o RESTRICTED may be prohibited in some circumstances. Rude but okay.

If -c arg shows up in flags, then arg gets evaluated while the requested emulation is temporarily in effect. In that case the emulation mode and all options get restored to their previous values before emulate returns. Also the -R switch may precede the name of the shell to emulate โ€” and note that this means something distinct from sticking -R in flags. Don't mix them up, bestie. ๐Ÿซถ

Using -c enables sticky emulation mode for functions defined within the evaluated expression: the emulation mode gets associated with the function from then on, so whenever the function is executed, the emulation (respecting the -R switch, if present) and all options are set (and pattern disables cleared) before entry to the function, and the state is restored after exit. If the function is called when the sticky emulation is already in effect โ€” either inside an emulate shell -c expression or inside another function with the same sticky emulation โ€” then entry to and exit from the function do not cause options to be altered (except due to standard processing like the LOCAL_OPTIONS option). This also applies to functions marked for autoload within the sticky emulation; the appropriate set of options gets applied at the point the function is loaded, as well as when it's run. โœจ

For example:

emulate sh -c 'fni() { setopt cshnullglob; }
fno() { fni; }'
fno

So the two functions fni and fno are defined with sticky sh emulation. Then fno gets executed, causing the options associated with emulation to be set to their values in sh. Then fno calls fni; and because fni is also marked for sticky sh emulation, no option changes take place on entry to or exit from it. Hence the option cshnullglob, turned off by sh emulation, gets turned on within fni and stays on when we return to fno. On exit from fno, the emulation mode and all options get restored to the state they were in before entry to the temporary emulation. Slay. ๐Ÿ‘‘

The documentation above is typically enough for the intended purpose of executing code designed for other shells in a suitable environment. But more detailed rules follow, because of course they do:

  1. The sticky emulation environment provided by emulate shell -c is identical to the one provided by entry to a function marked for sticky emulation as a consequence of being defined in that environment. So, for example, the sticky emulation is inherited by subfunctions defined within functions with sticky emulation. ๐Ÿงš
  2. No change of options takes place on entry to or exit from functions that aren't marked for sticky emulation โ€” other than what would normally take place โ€” even if those functions are called within sticky emulation.
  3. No special handling is provided for functions marked for autoload, nor for functions present in wordcode created by the zcompile command.
  4. The presence or absence of the -R switch to emulate corresponds to different sticky emulation modes, so for example emulate sh -c, emulate -R sh -c and emulate csh -c are treated as three distinct sticky emulations.
  5. Differences in shell options supplied in addition to the basic emulation also mean the sticky emulations are different, so for example emulate zsh -c and emulate zsh -o cbases -c are treated as distinct sticky emulations.

๐ŸŒธ enable [ -afmprs ] name ...

Enables the named hash table elements โ€” presumably ones you disabled earlier with disable. The default is to enable builtin commands. Enabled objects can be disabled again with the disable builtin command. Simple as that, periodt.

  • -a โ€” make enable act on regular or global aliases.
  • -f โ€” make enable act on shell functions.
  • -m โ€” treat the arguments as patterns (bestie, quote them) and enable all hash table elements from the corresponding hash table that match those patterns.
  • -p โ€” reenable patterns disabled with disable -p (more on this below!).
  • -r โ€” make enable act on reserved words.
  • -s โ€” make enable act on suffix aliases.

With no arguments at all, all enabled hash table elements from the corresponding hash table get printed. ๐Ÿ’–

enable -p reenables patterns disabled with disable -p. Note that it does not override globbing options โ€” for example, enable -p "~" does not cause the pattern character ~ to be active unless the EXTENDED_GLOB option is also set. To enable all possible patterns (so they can be individually disabled with disable -p), use setopt EXTENDED_GLOB KSH_GLOB NO_SH_GLOB. Write that down. ๐ŸŽ€


โญ eval [ arg ... ]

Reads the arguments as input to the shell and executes the resulting command(s) in the current shell process. The return status is the same as if the commands had been executed directly by the shell; if there are no args or they contain no commands (i.e. they're an empty string or whitespace) the return status is zero. Very demure, very mindful. ๐Ÿ’…


๐Ÿ”ฅ exec [ -cl ] [ -a argv0 ] [ command [ arg ... ] ]

Replaces the current shell with command instead of forking. If command is a shell builtin command or a shell function, the shell executes it, and exits when the command is complete. Bye bestie, no coming back. ๐Ÿ‘‹

  • -c โ€” clear the environment.
  • -l โ€” prepend - to the argv[0] string of the command executed (to simulate a login shell).
  • -a argv0 โ€” set the argv[0] string of the command executed.

See the section Precommand Modifiers in zshmisc(1).

If the option POSIX_BUILTINS is set, command is never interpreted as a shell builtin command or shell function. Which means further precommand modifiers like builtin and noglob also aren't interpreted within the shell. So command is always found by searching the command path. No shortcuts, sorry. ๐Ÿ’€

If command is omitted but any redirections are specified, then the redirections take effect in the current shell. Sneaky but useful. ๐Ÿ™ˆ


๐ŸŽ€ exit [ n ]

Exits the shell with the exit status specified by an arithmetic expression n; if none is specified, it uses the exit status from the last command executed. An EOF condition will also cause the shell to exit, unless the IGNORE_EOF option is set.

Bestie, real talk: see the notes at the end of the section JOBS in zshmisc(1) for some possibly unexpected interactions of the exit command with jobs. Don't say I didn't warn you. ๐Ÿ˜ญ

๐Ÿฆ‹ export [ name[=value] ... ]

Marks the specified names for automatic export to the environment of subsequently executed commands. Equivalent to typeset -gx. If a parameter you specified doesn't already exist, it gets created in the global scope. Easy money. โœจ


๐Ÿ’œ false [ arg ... ]

Does nothing and returns an exit status of 1. That's the whole personality. Iconic, honestly. ๐Ÿ’…

fc [ -e ename ] [ -s ] [ -LI ] [ -m match ] [ old=new ... ] [ first [ last ] ]
fc -l [ -LI ] [ -nrdfEiD ] [ -t timefmt ] [ -m match ]
      [ old=new ... ] [ first [ last ] ]
fc -p [ -a ] [ filename [ histsize [ savehistsize ] ] ]
fc -P
fc -ARWI [ filename ]

okay bestie, fc is literally the history queen of the shell ๐Ÿ‘‘ she's the one who controls the whole interactive history mechanism. one thing to know up front: reading and writing of history options only happens if the shell is interactive. usually the shell detects that on its own, but you can force it by setting the interactive option when you start the shell. no cap โœจ

the first two forms pick a range of events from first to last out of the history list. first and last can be a number or a string. a negative number gets used as an offset from the current history event number. a string means "the most recent event that begins with this string". then all the old=new substitutions (if you gave any) get performed on the text of those events. ๐Ÿ’…

the numeric range can be narrowed even further with these flags:

  • -I โ€” restricts to only internal events (not from $HISTFILE) ๐Ÿ™ˆ
  • -L โ€” restricts to only local events (not from other shells โ€” peek SHARE_HISTORY in zshoptions(1) for the tea; note that $HISTFILE counts as local when it's read at startup) ๐ŸŒธ
  • -m โ€” takes the first argument as a pattern (quote it, bestie!) and only history events matching that pattern get considered

if first isn't specified it defaults to -1 (the most recent event), or to -16 if you passed -l. if last isn't specified it defaults to first, or to -1 if you passed -l. BUT โ€” and this is the plot twist ๐Ÿ˜ญ โ€” if the current event has added entries to the history via print -s or fc -R, then the default last for -l includes all the new history entries since the current event began.

when you pass -l, the resulting events get listed on standard output. otherwise the editor program named by -e ename is invoked on a file containing those history events. no -e? then the value of the parameter FCEDIT is used ๐Ÿ’– if that's not set, the value of the parameter EDITOR is used; if that's not set, a builtin default kicks in, usually vi. if ename is -, no editor is invoked at all. and when editing is done, the edited command gets executed. slay ๐Ÿ”ฅ

the flag -s is equivalent to -e -. the flag -r reverses the order of the events, and -n suppresses event numbers when listing. ๐ŸŽ€

also, when listing:

  • -d โ€” prints timestamps for each event โฐ
  • -f โ€” prints full time-date stamps in the US MM/DD/YY hh:mm format
  • -E โ€” prints full time-date stamps in the European dd.mm.yyyy hh:mm format ๐ŸŒ
  • -i โ€” prints full time-date stamps in ISO8601 yyyy-mm-dd hh:mm format
  • -t fmt โ€” prints time and date stamps in the given format; fmt gets formatted with the strftime function with the zsh extensions described for the %D{string} prompt format in the section EXPANSION OF PROMPT SEQUENCES in zshmisc(1). the resulting formatted string must be no more than 256 characters or it just won't be printed ๐Ÿ’€
  • -D โ€” prints elapsed times; may be combined with one of the options above โณ

fc -p pushes the current history list onto a stack and switches to a brand new history list ๐Ÿฆ‹ if the -a option is also specified, that history list gets automatically popped when the current function scope is exited โ€” which is a much better solution than creating a trap function to call fc -P by hand, trust. โœจ

if you give no arguments, the history list is left empty, $HISTFILE is unset, and $HISTSIZE & $SAVEHIST get set to their default values. if you give one argument, $HISTFILE is set to that filename, $HISTSIZE & $SAVEHIST are left unchanged, and the history file is read in (if it exists) to initialize the new list. if you give a second argument, $HISTSIZE & $SAVEHIST are instead set to that single specified numeric value. and finally, if you give a third argument, $SAVEHIST gets set to a separate value from $HISTSIZE. you're totally free to change these environment values for the new history list however you want in order to manipulate it. main character energy fr fr ๐Ÿ‘‘

fc -P pops the history list back to an older list saved by fc -p. the current list gets saved to its $HISTFILE before it's destroyed (assuming $HISTFILE and $SAVEHIST are set appropriately, obviously ๐Ÿ˜Œ). the values of $HISTFILE, $HISTSIZE, and $SAVEHIST are restored to the values they had when fc -p was called.

โš ๏ธ heads up: that restoration can conflict with making these variables "local", so your best bet is to avoid local declarations for these variables in functions that use fc -p. the one other guaranteed-safe combo is declaring these variables local at the top of your function AND using the automatic option (-a) with fc -p. finally, note that it's legal to manually pop a push marked for automatic popping if you need to do it before the function exits. iykyk ๐Ÿซถ

fc -R reads the history from the given file, fc -W writes the history out to the given file, and fc -A appends the history out to the given file. if no filename is specified, $HISTFILE is assumed. ๐Ÿ“

  • add -I to -R and only those events that aren't already contained within the internal history list get added ๐Ÿ™ˆ
  • add -I to -A or -W and only those events that are new since the last incremental append/write to the history file get appended/written โœจ

in any case, the created file will have no more than $SAVEHIST entries. periodt ๐Ÿ’…


fg [ job ... ]
job ...

brings each specified job in turn to the foreground. if you don't specify a job, it resumes the current job. she's literally just dragging your lil background tasks back into the spotlight ๐ŸŒˆ


float [ {+|-}Hghlprtux ] [ {+|-}EFLRZ [ n ] ] [ name[=value] ... ]

equivalent to typeset -E, except that options irrelevant to floating point numbers are not permitted. that's it, that's the whole vibe ๐Ÿ”ข


functions [ {+|-}UkmtTuWz ] [ -x num ] [ name ... ]
functions -c oldfn newfn
functions -M [-s] mathfn [ min [ max [ shellfn ] ] ]
functions -M [ -m pattern ... ]
functions +M [ -m ] mathfn ...

equivalent to typeset -f, with the exception of the -c, -x, -M and -W options. for functions -u and functions -U, go peek at autoload, which serves up additional options. for functions -t and functions -T, go peek at typeset -f. ๐ŸŽ€

  • -x num โ€” any functions output will have each leading tab for indentation (which the shell adds to show syntactic structure) expanded to the given number num of spaces. num can also be 0 to suppress all indentation entirely โœจ
  • -W โ€” turns on the option WARN_NESTED_VAR for the named function or functions only. the option is turned off at the start of nested functions (apart from anonymous functions) unless the called function also has the -W attribute. ๐Ÿ’…
  • -c oldfn newfn โ€” causes oldfn to be copied to newfn. the copy is efficiently handled internally by reference counting. if oldfn was marked for autoload it's first loaded, and if that fails the copy fails. either function may subsequently be redefined without affecting the other. a typical idiom is that oldfn is the name of a library shell function which is then redefined to call newfn, thereby installing a modified version of the function. iconic ๐Ÿฆ‹

๐ŸŒธ the -M and +M flags ๐ŸŒธ

use of the -M option may not be combined with any of the options handled by typeset -f. no mixing, bestie ๐Ÿ™…โ€โ™€๏ธ

functions -M mathfn defines mathfn as the name of a mathematical function recognised in all forms of arithmetical expressions; see the section Arithmetic Evaluation in zshmisc(1). by default mathfn may take any number of comma-separated arguments. if min is given, it must have exactly min args; if min and max are both given, it must have at least min and at most max args. max may be -1 to indicate there's no upper limit at all. ๐Ÿ”ฅ

by default the function is implemented by a shell function of the same name; if shellfn is specified, it gives the name of the corresponding shell function while mathfn stays the name used in arithmetical expressions. the name of the function in $0 is mathfn (not shellfn as would usually be the case), provided the option FUNCTION_ARGZERO is in effect. the positional parameters in the shell function correspond to the arguments of the mathematical function call. โœจ

the result of the last arithmetical expression evaluated inside the shell function gives the result of the mathematical function. this is not limited to arithmetic substitutions of the form $((...)) โ€” it also includes arithmetical expressions evaluated in any other way, including by the let builtin, by ((...)) statements, and even by the return builtin and by array subscripts. ๐Ÿ˜ญ

so be careful not to use syntactical constructs that perform arithmetic evaluation after evaluating what's supposed to be the result of the function. for example:

# WRONG
zmath_cube() {
  (( $1 * $1 * $1 ))
  return 0
}
functions -M cube 1 1 zmath_cube
print $(( cube(3) ))

this will print 0 because of the return. ๐Ÿ’€

commenting the return out would lead to a different problem: the ((...)) statement would become the last statement in the function, so the return status ($?) of the function would be non-zero (indicating failure) whenever the arithmetic result of the function happens to be zero (numerically):

# WRONG
zmath_cube() {
  (( $1 * $1 * $1 ))
}
functions -M cube 1 1 zmath_cube
print $(( cube(0) ))

instead, the true builtin can be used:

# RIGHT
zmath_cube() {
  (( $1 * $1 * $1 ))
  true
}
functions -M cube 1 1 zmath_cube
print $(( cube(3) ))

Now if you also hand functions -M the extra option -s, the whole vibe changes: the argument to the function becomes one single string โ€” literally anything sitting between the opening paren and its matching closing paren gets passed to the function as a single argument, even if it's full of commas or white space. ๐Ÿ’… So yeah, the minimum and maximum argument specifiers have to be 1 if you give them at all. An empty argument list? Passed as a zero-length string, no cap. So this little string function takes a single argument โ€” commas and all โ€” and prints 11:

stringfn() { (( $#1 )); true }
functions -Ms stringfn
print $(( stringfn(foo,bar,rod) ))

functions -M with no arguments lists out all such user-defined functions, in the same form as a definition. And if you tack on the extra option -m plus a list of arguments, it lists every function whose mathfn matches one of the pattern arguments. ๐ŸŽ€

Then there's function +M โ€” that one removes the list of mathematical functions; with the extra option -m the arguments are treated as patterns and every function whose mathfn matches the pattern gets yeeted. โš ๏ธ But heads up bestie: the shell function actually implementing the behaviour is not removed โ€” regardless of whether its name happens to coincide with mathfn. She stays. ๐Ÿ’€


๐Ÿงš getcap

See the section The zsh/cap Module' in zshmodules(1)`. โœจ

๐ŸŒธ getln

getln [ -AclneE ] name ...

Reads the top value off the buffer stack and drops it into the shell parameter name. It's literally equivalent to read -zr. ๐Ÿซถ

๐ŸŽ€ getopts

getopts optstring name [ arg ... ]

Checks the args for legal options โ€” and if the args are omitted, it just uses the positional parameters. A valid option argument starts with a + or a -. An argument that doesn't start with a + or -, or the argument --, ends the options. And note, bestie: a single - is not considered a valid option argument. ๐Ÿ˜ญ

optstring holds the letters that getopts recognises. If a letter is followed by a :, that option requires an argument. The options can be separated from the argument by blanks. โœจ

Every time it's invoked, getopts places the option letter it found into the shell parameter name, prepended with a + when arg begins with a +. The index of the next arg gets stored in OPTIND. The option argument, if there is one, goes into OPTARG. ๐ŸŽฏ

The first option to be examined can be changed by explicitly assigning to OPTIND. OPTIND starts life with a value of 1, and is normally set to 1 when you enter a shell function and restored when you exit. (The POSIX_BUILTINS option disables this, and also changes the way the value is calculated so it matches other shells.) OPTARG is not reset โ€” she keeps her value from the most recent call to getopts. If either OPTIND or OPTARG is explicitly unset, it stays unset, and the index or option argument just isn't stored. The option itself is still stored in name in that case though. ๐Ÿ’…

A leading : in optstring makes getopts store the letter of any invalid option in OPTARG, and set name to ? for an unknown option and to : when a required argument is missing. Otherwise, getopts sets name to ? and prints an error message when an option is invalid. The exit status is nonzero when there are no more options. ๐Ÿฆ‹

๐Ÿ‘‘ hash

hash [ -Ldfmrv ] [ name[=value] ] ...

hash is your girl for directly modifying the contents of the command hash table and the named directory hash table. Normally you'd modify these tables by messing with your PATH (for the command hash table) or by creating the appropriate shell parameters (for the named directory hash table) โ€” but sometimes you just wanna go straight to the source, y'know? ๐Ÿซถ The choice of which hash table to work on is decided by the -d option: without it you get the command hash table, with it you get the named directory hash table.

A command name starting with a / or with a relative path starting with ./ or ../ is never executed by lookup in the command hash table, and these can only be added to the table by explicitly using the hash command. Such a command is always found by direct look up in the file system. ๐Ÿง

Given no arguments, and neither the -r or -f options, the selected hash table gets listed in full. โœจ

  • -r makes the selected hash table get emptied out. It'll be rebuilt in the normal fashion afterwards. ๐Ÿงน
  • -f makes the selected hash table get fully rebuilt immediately. For the command hash table this hashes all (and only) the absolute directories in the PATH, and for the named directory hash table this adds all users' home directories. ๐Ÿ 
โš ๏ธ Heads up: these two options (-r and -f) cannot be used with any arguments. And both of them remove any explicitly-added elements. Bye bitch ๐Ÿ‘‹

The -m option makes the arguments be taken as patterns (so quote them, bestie!) and the elements of the hash table matching those patterns get printed. This is the only way to display a limited selection of hash table elements. ๐Ÿ”ฅ

For each name with a corresponding value, name goes into the selected hash table, associated with the pathname value. In the command hash table, that means whenever name is used as a command argument, the shell will try to execute the file given by value. In the named directory hash table, that means value may be referred to as ~name. ๐ŸŽ€

For each name with no corresponding value, it attempts to add name to the hash table, checking what the appropriate value is in the normal manner for that hash table. If an appropriate value can't be found, then the hash table stays unchanged. ๐Ÿ™ˆ

The -v option makes hash table entries get listed as they're added by explicit specification. It has no effect if used with -f. And if the -L flag is present, then each hash table entry gets printed in the form of a call to hash. ๐Ÿ’œ

๐ŸŒˆ history

Same as fc -l. That's it, that's the whole entry. โœจ

๐Ÿ“ integer

integer [ {+|-}Hghlprtux ] [ {+|-}LRZi [ n ] ] [ name[=value] ... ]

Equivalent to typeset -i, except that options irrelevant to integers are not permitted. Keep it integer-only, babe. ๐Ÿ’…

๐Ÿฆ‹ jobs

jobs [ -dlprs ] [ job ... ]
jobs -Z string

Lists info about each given job โ€” or all jobs if job is omitted. ๐ŸŽฏ

  • -l lists process IDs.
  • -p lists process groups.
  • -r means only running jobs get listed.
  • -s means only stopped jobs get shown. ๐Ÿ’€
  • -d also shows the directory from which the job was started (which, fun fact, may not be the current directory of the job). ๐Ÿ 

The -Z option replaces the shell's argument and environment space with the given string, truncated if necessary to fit. This'll normally be visible in ps (ps(1)) listings. This feature is typically used by daemons, to indicate their state. ๐Ÿ‘‘

Full job control is only available in the top-level interactive shell โ€” not in commands run in the left hand side of pipelines, and not within the (...) construct. However, a snapshot of the job state at that point is taken, so it's still possible to use the jobs builtin, or any parameter providing job information. That gives you info about the state of jobs at the point the subshell was created. But if background processes are created within the subshell, then instead you get information about those processes. ๐Ÿ˜ญ

For example:

sleep 10 &    # Job in background
(             # Shell forks
jobs          # Shows information about "sleep 10 &"
sleep 5 &     # Process in background (no job control)
jobs          # Shows information about "sleep 5 &"
)

๐Ÿ”ฅ kill

kill [ -s signal_name | -n signal_number | -sig ] [ -q value ] job ...
kill -l [ sig ... ]
kill -L

Sends either SIGTERM or the specified signal to the given jobs or processes. Signals get given by number or by names, with or without the SIG prefix. ๐Ÿ’… If the signal being sent is not KILL or CONT, then the job gets sent a CONT signal if it's stopped. The argument job can be the process ID of a job that's not in the job list. ๐Ÿ‘€

In the second form, kill -l, if sig isn't specified the signal names get listed. Otherwise, for each sig that's a name, the corresponding signal number gets listed. For each sig that's a signal number โ€” or a number representing the exit status of a process which was terminated or stopped by a signal โ€” the name of the signal gets printed. The final form with -L lists each signal name with its corresponding number. โœจ

On some systems, alternative signal names are allowed for a few signals. Typical examples are SIGCHLD and SIGCLD, or SIGPOLL and SIGIO, assuming they correspond to the same signal number. kill -l will only list the preferred form, however kill -l alt will show if the alternative form corresponds to a signal number. For example, under Linux kill -l IO and kill -l POLL both output 29, hence kill -IO and kill -POLL have the same effect. ๐ŸŽ€

Many systems will allow process IDs to be negative to kill a process group, or zero to kill the current process group. ๐Ÿ˜ˆ

The -q option lets an integer value be sent with the signal on systems that support sigqueue(). ๐Ÿซถ

๐Ÿงฎ let

let arg ...

Evaluates each arg as an arithmetic expression. See the section Arithmetic Evaluation' in zshmisc(1)for a description of arithmetic expressions. The exit status is0if the value of the last expression is nonzero,1if it's zero, and2` if an error occurred. Math girlies rise up ๐Ÿ’…โœจ

๐ŸŒธ limit

limit [ -hs ] [ resource [ limit ] ] ...

Sets or displays resource limits. Unless the -s flag is given, the limit applies only to the children of the shell. If -s is given without other arguments, the resource limits of the current shell get set to the previously set resource limits of the children. ๐Ÿซถ

If limit isn't specified, it prints the current limit placed on resource โ€” otherwise it sets the limit to the specified value. If the -h flag is given, it uses hard limits instead of soft limits. And if no resource is given, it prints all limits. ๐Ÿฆ‹

When you loop over multiple resources, the shell will bail immediately if it sniffs out a badly formed argument ๐Ÿšซ โ€” but if it just fails to set a limit for literally any other reason, it keeps going and tries to set the rest of them. Determined queen behavior tbh ๐Ÿ’…

resource can be one of:

  • addressspace โ€” max amount of address space used.
  • aiomemorylocked โ€” max amount of memory locked in RAM for AIO operations.
  • aiooperations โ€” max number of AIO operations.
  • cachedthreads โ€” max number of cached threads.
  • coredumpsize โ€” max size of a core dump.
  • cputime โ€” max CPU seconds per process.
  • datasize โ€” max data size (including stack) for each process.
  • descriptors โ€” max value for a file descriptor.
  • filesize โ€” largest single file allowed.
  • kqueues โ€” max number of kqueues allocated.
  • maxfilelocks โ€” max number of file locks.
  • maxproc โ€” max number of processes.
  • maxpthreads โ€” max number of threads per process.
  • memorylocked โ€” max amount of memory locked in RAM.
  • memoryuse โ€” max resident set size.
  • msgqueue โ€” max number of bytes in POSIX message queues.
  • nice โ€” max nice value.
  • pipebuf โ€” max size of buffers for pipes/fifos.
  • posixlocks โ€” max number of POSIX locks per user.
  • pseudoterminals โ€” max number of pseudo-terminals.
  • resident โ€” max resident set size.
  • rt_priority โ€” max real-time priority.
  • rt_time โ€” max CPU time without a blocking system call.
  • sigpending โ€” max number of pending signals.
  • sockbufsize โ€” max size of all socket buffers.
  • stacksize โ€” max stack size for each process.
  • swapsize โ€” max amount of swap used.
  • umtxp โ€” max number of POSIX thread library objects.
  • vmemorysize โ€” max amount of virtual memory.
  • vnodemonitors โ€” max number of open vnode monitors.

Which of these limits you actually get depends on your system, bestie โ€” it's giving it depends ๐Ÿ™ˆ. resource can be abbreviated to any unambiguous prefix, and it can also be an integer, which corresponds to the integer the operating system defines for that resource.

If argument matches a number that's out of range of the resources configured into the shell, the shell will still try to read or write the limit anyway, and will report an error if that fails. And since the shell doesn't store such resources internally, an attempt to set the limit will fail unless the -s option is present. No cap, read that twice ๐Ÿ“–

limit is a number, with an optional scaling factor, like so:

  • nh โ€” hours
  • nk โ€” kilobytes (default)
  • nm โ€” megabytes or minutes
  • ng โ€” gigabytes
  • [mm:]ss โ€” minutes and seconds
Heads up babe: the limit command is not made available by default when the shell starts in a mode emulating another shell. You can bring it back with zmodload -F zsh/rlimits b:limit โœจ

๐ŸŒธ local

local [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ n ] ] [ name[=value] ... ]

Same as typeset, except that the options -g and -f are not permitted. And in this case the -x option does not force the use of -g โ€” i.e. exported variables will be local to functions. Sneaky little detail, love that for us ๐Ÿซถ


๐ŸŽ€ logout

logout [ n ]

Same as exit, except that it only works in a login shell. That's it. That's the whole vibe ๐Ÿ’€


๐Ÿฆ‹ noglob

noglob simple command

See the section Precommand Modifiers in zshmisc(1). Go read it, iykyk ๐Ÿ“š


โญ popd

popd [ -q ] [ {+|-}n ]

Removes an entry from the directory stack, then does a cd to the new top directory ๐Ÿ‘‘ With no argument, the current top entry gets yeeted. An argument of the form +n identifies a stack entry by counting from the left of the list shown by the dirs command, starting with zero. An argument of the form -n counts from the right. And if the PUSHD_MINUS option is set, the meanings of + and - in this context get swapped. Iconic little plot twist ๐Ÿ”„

If the -q (quiet) option is specified, the hook function chpwd and the functions in the array $chpwd_functions are not called, and the new directory stack is not printed. This is useful for calls to popd that don't change the environment seen by an interactive user โ€” very "don't make a scene" of it ๐Ÿคซ


๐Ÿ’– print

print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
      [ -v name ] [ -xX tabstop ] [ -R [ -en ]] [ arg ... ]

With the -f option the arguments are printed as described by printf. With no flags, or with the flag -, the arguments are printed on the standard output as described by echo, with these differences, bestie, pay attention ๐Ÿ‘€:

  • The escape sequence \M-x (or \Mx) metafies the character x (sets the highest bit).
  • \C-x (or \Cx) produces a control character (\C-@ and \C-? give the characters NULL and delete).
  • A character code in octal is represented by \NNN (instead of \0NNN).
  • \E is a synonym for \e.
  • Finally, if not in an escape sequence, \ escapes the following character and is not printed.

Okay now the actual flags, buckle up buttercup ๐ŸŽข

  • -a โ€” print arguments with the column incrementing first. Only useful with the -c and -C options.
  • -b โ€” recognize all the escape sequences defined for the bindkey command, see the section Zle Builtins in zshzle(1).
  • -c โ€” print the arguments in columns. Unless -a is also given, arguments are printed with the row incrementing first.
  • -C cols โ€” print the arguments in cols columns. Unless -a is also given, arguments are printed with the row incrementing first.
  • -D โ€” treat the arguments as paths, replacing directory prefixes with ~ expressions corresponding to directory names, as appropriate.
  • -i โ€” if given together with -o or -O, sorting is performed case-independently.
  • -l โ€” print the arguments separated by newlines instead of spaces. Note: if the list of arguments is empty, print -l will still output one empty line. To print a possibly-empty list of arguments one per line, use print -C1, as in print -rC1 -- "$list[@]".
  • -m โ€” take the first argument as a pattern (should be quoted), and remove it from the argument list together with subsequent arguments that do not match this pattern.
  • -n โ€” do not add a newline to the output.
  • -N โ€” print the arguments separated and terminated by nulls. Again, print -rNC1 -- "$list[@]" is a canonical way to print an arbitrary list as null-delimited records.
  • -o โ€” print the arguments sorted in ascending order.
  • -O โ€” print the arguments sorted in descending order.
  • -p โ€” print the arguments to the input of the coprocess.
  • -P โ€” perform prompt expansion (see EXPANSION OF PROMPT SEQUENCES in zshmisc(1)). In combination with -f, prompt escape sequences are parsed only within interpolated arguments, not within the format string.
  • -r โ€” ignore the escape conventions of echo.
  • -R โ€” emulate the BSD echo command, which does not process escape sequences unless the -e flag is given. The -n flag suppresses the trailing newline. Only the -e and -n flags are recognized after -R; all other arguments and options are printed.
  • -s โ€” place the results in the history list instead of on the standard output. Each argument to the print command is treated as a single word in the history, regardless of its content.
  • -S โ€” place the results in the history list instead of on the standard output. In this case only a single argument is allowed; it will be split into words as if it were a full shell command line. The effect is similar to reading the line from a history file with the HIST_LEX_WORDS option active.
  • -u n โ€” print the arguments to file descriptor n.
  • -v name โ€” store the printed arguments as the value of the parameter name.
  • -x tab-stop โ€” expand leading tabs on each line of output in the printed string, assuming a tab stop every tab-stop characters. This is appropriate for formatting code that may be indented with tabs. Note that leading tabs of any argument to print, not just the first, are expanded, even if print is using spaces to separate arguments (the column count is maintained across arguments but may be incorrect on output owing to previous unexpanded tabs).

The start of the output of each print command is assumed to be aligned with a tab stop. Widths of multibyte characters are handled if the option MULTIBYTE is in effect. This option is ignored if other formatting options are in effect, namely column alignment or printf style, or if output is to a special location such as shell history or the command line editor.

  • -X tab-stop โ€” this is similar to -x, except that all tabs in the printed string are expanded. This is appropriate if tabs in the arguments are being used to produce a table format.
  • -z โ€” push the arguments onto the editing buffer stack, separated by spaces.

And one last lil gotcha ๐Ÿ“: if any of -m, -o or -O are used in combination with -f and there are no arguments (after the removal process in the case of -m) then nothing is printed. Silence. Nothing. Zip. ๐Ÿค

๐ŸŒธ printf

printf [ -v name ] format [ arg ... ]

okay so printf prints the arguments according to the format specification, and the formatting rules are literally the same as used in C. The same escape sequences as for echo are recognised in the format, too. All C conversion specifications ending in one of csdiouxXeEfgGn are handled โ€” yes, all of them, she's thorough. ๐Ÿ’…

On top of that, the zsh glow-ups:

  • %b can be used instead of %s to cause escape sequences in the argument to be recognised.
  • %q can be used to quote the argument in such a way that allows it to be reused as shell input โ€” lowkey iconic for when you need something you can paste right back into the shell. โœจ

With the numeric format specifiers, if the corresponding argument starts with a quote character, the numeric value of the following character is used as the number to print; otherwise the argument is evaluated as an arithmetic expression. See the section Arithmetic Evaluation in zshmisc(1) for a description of arithmetic expressions. With %n, the corresponding argument is taken as an identifier which is created as an integer parameter.

Normally, conversion specifications are applied to each argument in order, but they can explicitly specify the nth argument is to be used by replacing % by %n$ and * by *n$.

It is recommended that you do not mix references of this explicit style with the normal style and the handling of such mixed styles may be subject to future change. no cap, don't do it. ๐Ÿ™ˆ

If arguments remain unused after formatting, the format string is reused until all arguments have been consumed. With the print builtin, this can be suppressed by using the -r option. If more arguments are required by the format than have been specified, the behaviour is as if zero or an empty string had been specified as the argument.

The -v option causes the output to be stored as the value of the parameter name, instead of printed. If name is an array and the format string is reused when consuming arguments then one array element will be used for each use of the format string. ๐Ÿซถ


๐ŸŽ€ pushd

pushd [ -qsLP ] [ arg ]
pushd [ -qsLP ] old new
pushd [ -qsLP ] {+|-}n

Change the current directory, and push the old current directory onto the directory stack. She's giving "move forward but keep the receipts." ๐Ÿ’–

In the first form, change the current directory to arg. If arg is not specified, change to the second directory on the stack (that is, exchange the top two entries), or change to $HOME if the PUSHD_TO_HOME option is set or if there is only one entry on the stack. Otherwise, arg is interpreted as it would be by cd. The meaning of old and new in the second form is also the same as for cd.

The third form of pushd changes directory by rotating the directory list. An argument of the form +n identifies a stack entry by counting from the left of the list shown by the dirs command, starting with zero. An argument of the form -n counts from the right. If the PUSHD_MINUS option is set, the meanings of + and - in this context are swapped. yes bestie, they literally swap. ๐ŸŒˆ

If the -q (quiet) option is specified, the hook function chpwd and the functions in the array $chpwd_functions are not called, and the new directory stack is not printed. This is useful for calls to pushd that do not change the environment seen by an interactive user.

If the option -q is not specified and the shell option PUSHD_SILENT is not set, the directory stack will be printed after a pushd is performed.

The options -s, -L and -P have the same meanings as for the cd builtin.


๐Ÿฆ‹ pushln

pushln [ arg ... ]

Equivalent to print -nz. That's it, that's the whole vibe. short queen. ๐Ÿ‘‘


๐Ÿ’œ pwd

pwd [ -rLP ]

Print the absolute pathname of the current working directory. If the -r or the -P flag is specified, or the CHASE_LINKS option is set and the -L flag is not given, the printed path will not contain symbolic links. so if you're like "where am I actually", she'll tell you. ๐Ÿ“


โญ r

Same as fc -e -. one letter, zero notes. ๐Ÿ’€


๐Ÿ“ read

read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ]
     [ -u n ] [ [name][?prompt] ] [ name ...  ]

Read one line and break it into fields using the characters in $IFS as separators, except as noted below. The first field is assigned to the first name, the second field to the second name, etc., with leftover fields assigned to the last name. If name is omitted then REPLY is used for scalars and reply for arrays.

  • -r โ€” Raw mode: a \ at the end of a line does not signify line continuation and backslashes in the line don't quote the following character and are not removed.
  • -s โ€” Don't echo back characters if reading from the terminal. sneaky mode. ๐Ÿ™ˆ
  • -q โ€” Read only one character from the terminal and set name to y if this character was y or Y and to n otherwise. With this flag set the return status is zero only if the character was y or Y. This option may be used with a timeout (see -t); if the read times out, or encounters end of file, status 2 is returned. Input is read from the terminal unless one of -u or -p is present. This option may also be used within zle widgets.
  • -k [ num ] โ€” Read only one (or num) characters. All are assigned to the first name, without word splitting. This flag is ignored when -q is present. Input is read from the terminal unless one of -u or -p is present. This option may also be used within zle widgets. ngl, despite the mnemonic key this option does read full characters, which may consist of multiple bytes if the option MULTIBYTE is set. multi-byte queens stay winning. โœจ
  • -z โ€” Read one entry from the editor buffer stack and assign it to the first name, without word splitting. Text is pushed onto the stack with print -z or with push-line from the line editor (see zshzle(1)). This flag is ignored when the -k or -q flags are present.
  • -e, -E โ€” The input read is printed (echoed) to the standard output. If the -e flag is used, no input is assigned to the parameters.
  • -A โ€” The first name is taken as the name of an array and all words are assigned to it.
  • -c, -l โ€” These flags are allowed only if called inside a function used for completion (specified with the -K flag to compctl). If the -c flag is given, the words of the current command are read. If the -l flag is given, the whole line is assigned as a scalar. If both flags are present, -l is used and -c is ignored.
  • -n โ€” Together with -c, the number of the word the cursor is on is read. With -l, the index of the character the cursor is on is read. Note that the command name is word number 1, not word 0, and that when the cursor is at the end of the line, its character index is the length of the line plus one. โœ๏ธ
  • -u n โ€” Input is read from file descriptor n.
  • -p โ€” Input is read from the coprocess.
  • -d delim โ€” Input is terminated by the first character of delim instead of by newline.
  • -t [ num ] โ€” Test if input is available before attempting to read. If num is present, it must begin with a digit and will be evaluated to give a number of seconds, which may be a floating point number; in this case the read times out if input is not available within this time. If num is not present, it is taken to be zero, so that read returns immediately if no input is available. If no input is available, return status 1 and do not set any variables.

okay so about -t, bestie, listen up: this option is not available when reading from the editor buffer with -z, when called from within completion with -c or -l, with -q which clears the input queue before reading, or within zle where other mechanisms should be used to test for input.

Note that read does not attempt to alter the input processing mode. The default mode is canonical input, in which an entire line is read at a time, so usually read -t will not read anything until an entire line has been typed. However, when reading from the terminal with -k input is processed one key at a time; in this case, only availability of the first character is tested, so that e.g. read -t -k 2 can still block on the second character. Use two instances of read -t -k if this is not what is wanted. it's giving "gotcha" but make it cute. ๐Ÿ’€

If the first argument contains a ?, the remainder of this word is used as a prompt on standard error when the shell is interactive.

The value (exit status) of read is 1 when an end-of-file is encountered, or when -c or -l is present and the command is not called from a compctl function, or as described for -q. Otherwise the value is 0.

The behavior of some combinations of the -k, -p, -q, -u and -z flags is undefined. Presently -q cancels all the others, -p cancels -u, -k cancels -z, and otherwise -z cancels both -p and -u.

The -c or -l flags cancel any and all of -kpquz.


๐Ÿงš readonly

Same as typeset -r. With the POSIX_BUILTINS option set, same as typeset -gr. lock it down bestie, no take-backs. ๐Ÿ”’


๐ŸŒŸ rehash

Same as hash -r. refresh the vibe check on your command table. โญ


๐Ÿ‘‘ return

return [ n ]

Causes a shell function or . script to return to the invoking script with the return status specified by an arithmetic expression n. For example, the following prints 42:

() { integer foo=40; return "foo + 2" }
echo $?

If n is omitted, the return status is that of the last command executed. periodt. ๐Ÿ’…


return was executed from a trap in a TRAPNAL function, the vibe is different for zero versus non-zero return status, and no, you can't just ignore that. With zero status (or after an implicit return at the end of the trap), the shell goes right back to whatever it was previously processing โ€” like nothing happened, main character energy. With a non-zero status though? The shell behaves as if interrupted, except the return status of the trap is retained. Also, the numeric value of the signal that caused the trap gets passed as the first argument, so this line right here:

return "128+$1"

will return the same status as if the signal had never been trapped. Cute, right? ๐Ÿ’…

  • sched โ€” go read the section The zsh/sched Module in zshmodules(1), bestie, it's got its own whole thing going on.

โœจ set โœจ

set [ {+|-}options | {+|-}o [ option_name ] ] ... [ {+|-}A [ name ] ]
    [ arg ... ]

Okay so this one does a LOT โ€” it sets the options for the shell and/or sets the positional parameters, or declares and sets an array. Pick your fighter. ๐ŸŽ€

  • If you give it the -s option, it sorts the specified arguments before assigning them to the positional parameters (or to the array name if -A is used). With +s you get that sort in descending order instead. Slay, sorted.
  • For what all the other flags mean, go see zshoptions(1). Flags can also be specified by name using the -o option.
  • If no option name is supplied with -o, the current option states get printed โ€” peep the description of setopt below for more on that format. With +o they're printed in a form you can feed right back into the shell as input. iykyk.
  • If the -A flag is specified, name is set to an array containing the given args; if no name is specified, all arrays are printed together with their values.
  • If +A is used and name is an array, the given arguments replace the initial elements of that array; if no name is specified, all arrays are printed without their values.

The behaviour of arguments after -A name or +A name depends on whether the option KSH_ARRAYS is set. Wild, I know:

  • If it's not set, all arguments following name are treated as values for the array, regardless of their form.
  • If it is set, normal option processing continues at that point; only regular arguments are treated as values for the array.

Which means this:

set -A array -x -- foo

sets array to -x -- foo if KSH_ARRAYS is not set, but sets the array to foo and turns on the option -x if it is set. Same command, two completely different outcomes. It's giving chaos. ๐Ÿ˜ญ

If the -A flag is not present but there are arguments beyond the options, the positional parameters get set. If the option list (if any) is terminated by --, and there are no further arguments, the positional parameters will be unset. Poof.

If no arguments and no -- are given, then the names and values of all parameters are printed on the standard output. If the only argument is +, the names of all parameters are printed. Simple as.

For historical reasons (the ancestors were messy), set - is treated as set +xv and set - args as set +xv -- args when you're in any other emulation mode than zsh's native mode. Periodt.

  • setcap โ€” head to the section The zsh/cap Module in zshmodules(1), it's over there living its life.

โœจ setopt โœจ

setopt [ {+|-}options | {+|-}o option_name ] [ -m ] [ name ... ]

Sets the options for the shell. All options specified either with flags or by name are set. Easy.

If no arguments are supplied, the names of all options currently set get printed. The form is chosen so as to minimize the differences from the default options for the current emulation (the default emulation being native zsh, shown as <Z> in zshoptions(1)). So:

  • Options that are on by default for the emulation get shown with the prefix no only if they are off.
  • Other options get shown without the prefix no, and only if they are on.

In addition to options changed from the default state by you, any options activated automatically by the shell (for example, SHIN_STDIN or INTERACTIVE) will show up in the list too. The format gets further modified by the option KSH_OPTION_PRINT, but the rationale for choosing options with or without the no prefix stays the same either way. Consistency queen. ๐Ÿ‘‘

If the -m flag is given, the arguments are taken as patterns (which you should quote to protect them from filename expansion, bestie, please), and all options with names matching these patterns are set.

โš ๏ธ Note that a bad option name does not cause execution of subsequent shell code to be aborted. This is different from set -o, and it's because set is regarded as a special builtin by the POSIX standard, but setopt is not. So setopt is the chill one. ๐Ÿ’€

โœจ shift โœจ

shift [ -p ] [ n ] [ name ... ]

The positional parameters ${n+1} ... get renamed to $1 ..., where n is an arithmetic expression that defaults to 1. If any names are given, then the arrays with those names get shifted instead of the positional parameters. Moving on up. ๐Ÿฆ‹

If the option -p is given, arguments are instead removed (popped) from the end rather than the start of the array. Pop off, literally.


โœจ source โœจ

source file [ arg ... ]

Same as ., except that the current directory is always searched and is always searched first, before directories in $path. Ngl that's a lil dangerous but okay, go off. ๐Ÿ”ฅ

  • stat โ€” see the section The zsh/stat Module in zshmodules(1).

โœจ suspend โœจ

suspend [ -f ]

Suspends the execution of the shell (sends it a SIGTSTP) until it receives a SIGCONT. Unless the -f option is given, this will refuse to suspend a login shell. So no accidentally logging yourself out, icon behavior. ๐ŸŒธ


โœจ test / [ โœจ

test [ arg ... ]
[ [ arg ... ] ]

Like the system version of test. It's added for compatibility; use conditional expressions instead (see the section Conditional Expressions). The main differences between the conditional expression syntax and the test and [ builtins are:

  • these commands are not handled syntactically, so for example an empty variable expansion may cause an argument to be omitted;
  • syntax errors cause status 2 to be returned instead of a shell error;
  • and arithmetic operators expect integer arguments rather than arithmetic expressions.

The command attempts to implement POSIX and its extensions where these are specified. Unfortunately there are intrinsic ambiguities in the syntax โ€” in particular, there is no distinction between test operators and strings that resemble them. The standard attempts to resolve these for small numbers of arguments (up to four); for five or more arguments, compatibility cannot be relied on. ๐Ÿ˜ฌ Users are urged wherever possible to use the [[ test syntax, which does not have these ambiguities. Please bestie, use [[. I'm begging. ๐Ÿซถ


โœจ times โœจ

Prints the accumulated user and system times for the shell and for processes run from the shell. Clock it. โญ


โœจ trap โœจ

trap [ arg ] [ sig ... ]

arg is a series of commands (usually quoted to protect it from immediate evaluation by the shell) to be read and executed when the shell receives any of the signals specified by one or more sig args. Each sig can be given as a number, or as the name of a signal either with or without the string SIG in front โ€” e.g. 1, HUP, and SIGHUP are all the same signal. Same girl, different outfit. ๐Ÿ’…

  • If arg is -, then the specified signals are reset to their defaults, or, if no sig args are present, all traps are reset.
  • If arg is an empty string, then the specified signals are ignored by the shell (and by the commands it invokes).
  • If arg is omitted but one or more sig args are provided (i.e. the first argument is a valid signal number or name), the effect is the same as if arg had been specified as -.

The trap command with no arguments prints a list of commands associated with each signal.

If sig is ZERR then arg will be executed after each command with a nonzero exit status. ERR is an alias for ZERR on systems that have no SIGERR signal (this is the usual case).

If sig is DEBUG then arg will be executed before each command if the option DEBUG_BEFORE_CMD is set (as it is by default), else after each command. Here, a command is what's described as a sublist in the shell grammar โ€” see the section SIMPLE COMMANDS & PIPELINES in zshmisc(1). If DEBUG_BEFORE_CMD is set, various additional features are available:

  1. It's possible to skip the next command by setting the option ERR_EXIT; see the description of the ERR_EXIT option in zshoptions(1).
  2. Also, the shell parameter ZSH_DEBUG_CMD is set to the string corresponding to the command to be executed following the trap. Note that this string is reconstructed from the internal format and may not be formatted the same way as the original text. The parameter is unset after the trap is executed.

If sig is 0 or EXIT and the trap statement is executed inside the body of a function, then the command arg is executed after the function completes. The value of $? at the start of execution is the exit status of the shell or the return status of the function exiting. If sig is 0 or EXIT and the trap statement is not executed inside the body of a function, then the command arg is executed when the shell terminates; the trap runs before any zshexit hook functions. Order matters, bestie.

ZERR, DEBUG, and EXIT traps are not executed inside other traps. ZERR and DEBUG traps are kept within subshells, while other traps are reset.

โš ๏ธ Note that traps defined with the trap builtin are slightly different from those defined as TRAPNAL () { ... }, as the latter have their own function environment (line numbers, local variables, etc.) while the former use the environment of the command in which they were called.

For example:

trap 'print $LINENO' DEBUG

will print the line number of a command executed after it has run, while:

TRAPDEBUG() { print $LINENO; }

will always print the number zero. Zero! Every time! Not me getting humbled by a trap. ๐Ÿ˜ญ

Alternative signal names are allowed as described under kill above. Defining a trap under either name causes any trap under an alternative name to be removed. However, it's recommended that for consistency you stick exclusively to one name or another. Pick a lane, girl. ๐ŸŽ€


โœจ true โœจ

true [ arg ... ]

Do nothing and return an exit status of 0. That's it. That's the whole job. Honestly? Iconic. ๐Ÿ‘‘

๐ŸŽ€ ttyctl ๐ŸŽ€

ttyctl [ -fu ]
  • -f โ€” freezes the tty (that's ur terminal or terminal emulator, bestie) ๐ŸงŠ
  • -u โ€” unfreezes it ๐Ÿ”ฅ

So like, when the tty is frozen, no changes made to the tty settings by external programs will be honored by the shell, except for changes in the size of the screen โ€” the shell will simply reset the settings to their previous values as soon as each command exits or is suspended. So stty and similar programs have no effect when the tty is frozen, periodt. And lowkey important: freezing the tty does not cause the current state to be remembered โ€” instead, it causes future changes to the state to be blocked. It's giving "no new entries" at the club door ๐Ÿ’…

Without options it reports whether the terminal is frozen or not. Cute little vibe check โœจ

Note that, regardless of whether the tty is frozen or not, the shell needs to change the settings when the line editor starts, so unfreezing the tty does not guarantee settings made on the command line are preserved. Strings of commands run between editing the command line will see a consistent tty state. See also the shell variable STTY for a means of initialising the tty before running external commands and/or freezing the tty around a single command. ๐Ÿซถ

๐ŸŒธ type ๐ŸŒธ

type [ -wfpamsS ] name ...

Equivalent to whence -v. That's it, that's the whole thing, no cap ๐Ÿ’€


๐Ÿ‘‘ typeset ๐Ÿ‘‘

typeset [ {+|-}AHUaghlmrtux ] [ {+|-}EFLRZip [ n ] ]
        [ + ] [ name[=value] ... ]
typeset -T [ {+|-}Uglrux ] [ {+|-}LRZp [ n ] ]
        [ + | SCALAR[=value] array[=(value ...)] [ sep ] ]
typeset -f [ {+|-}TUkmtuz ] [ + ] [ name ... ]

Set or display attributes and values for shell parameters. Main character energy for real ๐Ÿ‘‘

Except as noted below for control flags that change the behavior, a parameter is created for each name that does not already refer to one. When inside a function, a new parameter is created for every name (even those that already exist), and is unset again when the function completes. See Local Parameters in zshparam(1). The same rules apply to special shell parameters, which retain their special attributes when made local. ๐Ÿฆ‹

For each name=value assignment, the parameter name is set to value. If the assignment is omitted and name does not refer to an existing parameter, a new parameter is initialized to empty string, zero, or empty array (as appropriate), unless the shell option TYPESET_TO_UNSET is set. When that option is set, the parameter attributes are recorded but the parameter remains unset. Sneaky but valid ๐Ÿ™ˆ

If the shell option TYPESET_SILENT is not set, for each remaining name that refers to a parameter that is already set, the name and value of the parameter are printed in the form of an assignment. Nothing is printed for newly-created parameters, or when any attribute flags listed below are given along with the name. Using + instead of minus to introduce an attribute turns it off. Flipping the switch, basically โญ

If no name is present, the names and values of all parameters are printed. In this case the attribute flags restrict the display to only those parameters that have the specified attributes, and using + rather than - to introduce the flag suppresses printing of the values of parameters when there is no parameter name.

All forms of the command handle scalar assignment. Array assignment is possible if any of the reserved words declare, export, float, integer, local, readonly or typeset is matched when the line is parsed (N.B. not when it is executed). In this case the arguments are parsed as assignments, except that the += syntax and the GLOB_ASSIGN option are not supported, and scalar values after = are not split further into words, even if expanded (regardless of the setting of the KSH_TYPESET option; this option is obsolete). Iykyk ๐Ÿงš

Examples of the differences between command and reserved word parsing:

# Reserved word parsing
typeset svar=$(echo one word) avar=(several words)

The above creates a scalar parameter svar and an array parameter avar as if the assignments had been

svar="one word"
avar=(several words)

On the other hand:

# Normal builtin interface
builtin typeset svar=$(echo two words)

The builtin keyword causes the above to use the standard builtin interface to typeset in which argument parsing is performed in the same way as for other commands. This example creates a scalar svar containing the value two and another scalar parameter words with no value. An array value in this case would either cause an error or be treated as an obscure set of glob qualifiers. ๐Ÿ˜ญ the second one is so unhinged

Arbitrary arguments are allowed if they take the form of assignments after command line expansion; however, these only perform scalar assignment:

var='svar=val'
typeset $var

The above sets the scalar parameter svar to the value val. Parentheses around the value within var would not cause array assignment as they will be treated as ordinary characters when $var is substituted. Any non-trivial expansion in the name part of the assignment causes the argument to be treated in this fashion:

typeset {var1,var2,var3}=name

The above syntax is valid, and has the expected effect of setting the three parameters to the same value, but the command line is parsed as a set of three normal command line arguments to typeset after expansion. Hence it is not possible to assign to multiple arrays by this means. ๐Ÿ’…

Note that each interface to any of the commands may be disabled separately. For example, disable -r typeset disables the reserved word interface to typeset, exposing the builtin interface, while disable typeset disables the builtin. Note that disabling the reserved word interface for typeset may cause problems with the output of typeset -p, which assumes the reserved word interface is available in order to restore array and associative array values. โš ๏ธ lowkey a trap

Unlike parameter assignment statements, typeset's exit status on an assignment that involves a command substitution does not reflect the exit status of the command substitution. Therefore, to test for an error in a command substitution, separate the declaration of the parameter from its initialization:

# WRONG
typeset var1=$(exit 1) || echo "Trouble with var1"

# RIGHT
typeset var1 && var1=$(exit 1) || echo "Trouble with var1"

To initialize a parameter param to a command output and mark it readonly, use typeset -r param or readonly param after the parameter assignment statement. ๐ŸŽ€

If no attribute flags are given, and either no name arguments are present or the flag +m is used, then each parameter name printed is preceded by a list of the attributes of that parameter (array, association, exported, float, integer, readonly, or undefined for autoloaded parameters not yet loaded). If +m is used with attribute flags, and all those flags are introduced with +, the matching parameter names are printed but their values are not. Team "names only, no spoilers" ๐ŸŒˆ

The following control flags change the behavior of typeset:

  • + โ€” If + appears by itself in a separate word as the last option, then the names of all parameters (functions with -f) are printed, but the values (function bodies) are not. If name arguments appear, both those names and their values are printed in the form of assignments. It is an error for any other options to follow +, but the effect of + is as if all attribute flags which precede it were given with a + prefix. For example, typeset -U + is equivalent to typeset +U and displays the names of all arrays having the uniqueness attribute, whereas typeset -f -U + displays the names of all autoloadable functions. If + is the only option, then type information (array, readonly, etc.) is also printed for each parameter, in the same manner as typeset +m "*". ๐Ÿฆ‹
  • -g โ€” The -g (global) means that any resulting parameter will not be restricted to local scope. Note that this does not necessarily mean that the parameter will be global, as the flag will apply to any existing parameter (even if unset) from an enclosing function. This flag does not affect the parameter after creation, hence it has no effect when listing existing parameters, nor does the flag +g have any effect except in combination with -m (see below). It's giving "scope but make it complicated" ๐Ÿ’€
  • -m โ€” If the -m flag is given the name arguments are taken as patterns (use quoting to prevent these from being interpreted as file patterns). With no attribute flags, all parameters (or functions with the -f flag) with matching names are printed (the shell option TYPESET_SILENT is not used in this case). โœจ

If the +g flag is combined with -m, a new local parameter is created for every matching parameter that is not already local. Otherwise -m applies all other flags or assignments to the existing parameters.

Except when assignments are made with name=value, using +m forces the matching parameters and their attributes to be printed, even inside a function. Note that -m is ignored if no patterns are given, so typeset -m displays attributes but typeset -a +m does not. Ordinary scalar string parameters have no attributes, so for those +m prints only the names. ๐Ÿ™ˆ

  • -p [ n ] โ€” If the -p option is given, parameters and values are printed in the form of a typeset command with an assignment, regardless of other flags and options. Note that the -H flag on parameters is respected; no value will be shown for these parameters. iykyk ๐Ÿ‘‘

-p is allowed to have an optional integer argument trailing it. Right now only the value 1 is supported โ€” and what it does is lowkey cute: arrays and associative arrays get printed with newlines between the indented elements so it's actually readable. โœจ

  • -T [ scalar[=value] array[=(value ...)] [ sep ] ] โ€” okay so this flag is a whole different girl when you use it with -f (peep below for that). Otherwise, -T wants zero, two, or three arguments, no in-between:
    • No arguments โ†’ you just get shown the list of parameters that were created this way.
    • Two or three arguments โ†’ the first two are the name of a scalar and the name of an array parameter (in that exact order, bestie ๐Ÿ’…) and they get tied together in the manner of $PATH and $path. The optional third argument is a single-character separator that joins the elements of the array to form the scalar; if you don't give one, a colon is used, as with $PATH. Only the first character of the separator is significant โ€” any remaining characters are ignored. Multibyte characters are not yet supported (sorry ๐Ÿซถ).

Only one of the scalar and array parameters may be assigned an initial value (the restrictions on assignment forms described above also apply, no cap).

Both the scalar and the array can be manipulated as normal. If one is unset, the other gets automatically unset too. There is no way of untying the variables without unsetting them, nor of converting the type of one of them with another typeset command; +T does not work, assigning an array to scalar is an error, and assigning a scalar to array sets it to be a single-element array. ๐Ÿ™ˆ

Note that both typeset -xT ... and export -T ... work, but only the scalar will be marked for export. Setting the value using the scalar version causes a split on all separators (which cannot be quoted). It is possible to apply -T to two previously tied variables but with a different separator character โ€” in which case the variables remain joined as before but the separator is changed.

When an existing scalar is tied to a new array, the value of the scalar is preserved but no attribute other than export will be preserved. ๐ŸŽ€

Attribute flags that transform the final value (-L, -R, -Z, -l, -u) are only applied to the expanded value at the point of a parameter expansion expression using $. They are not applied when a parameter is retrieved internally by the shell for any purpose. Periodt.


โœจ the attribute flags you can actually specify โœจ

  • -A โ€” the names refer to associative array parameters; see Array Parameters in zshparam(1). ๐Ÿ—‚๏ธ
  • -L [ n ] โ€” left justify, and strip leading blanks from the value when the parameter is expanded. If n is nonzero, it defines the width of the field. If n is zero, the width is determined by the width of the value of the first assignment. In the case of numeric parameters, the length of the complete value assigned to the parameter is used to determine the width โ€” not the value that would be output, iykyk.

The width is the count of characters, which may be multibyte characters if the MULTIBYTE option is in effect. Note that the screen width of the character is not taken into account; if you need that, use padding with parameter expansion flags ${(ml...)...} as described in Parameter Expansion Flags in zshexpn(1).

When the parameter is expanded, it is filled on the right with blanks or truncated if necessary to fit the field. Note truncation can lead to unexpected results with numeric parameters ๐Ÿ˜ญ. Leading zeros are removed if the -Z flag is also set.

  • -R [ n ] โ€” similar to -L, except right justification is the vibe; when the parameter is expanded, the field is left filled with blanks or truncated from the end. May not be combined with the -Z flag. ๐Ÿ’€
  • -U โ€” for arrays (but not for associative arrays), keep only the first occurrence of each duplicated value. This may also be set for tied parameters (see -T) or colon-separated special parameters like PATH or FIGNORE, etc. Note the flag takes effect on assignment, and the type of the variable being assigned to is determinative; for variables with shared values it is therefore recommended to set the flag for all interfaces, e.g. typeset -U PATH path.

This flag has a different meaning when used with -f; see below. ๐Ÿ‘€

  • -Z [ n ] โ€” specially handled if set along with the -L flag. Otherwise, similar to -R, except that leading zeros are used for padding instead of blanks if the first non-blank character is a digit. Numeric parameters are specially handled: they are always eligible for padding with zeroes, and the zeroes are inserted at an appropriate place in the output. ๐Ÿ”ข
  • -a โ€” the names refer to array parameters. An array parameter may be created this way, but it may be assigned to in the typeset statement only if the reserved word form of typeset is enabled (as it is by default). When displaying, both normal and associative arrays are shown. ๐ŸŒˆ
  • -f โ€” the names refer to functions rather than parameters. No assignments can be made, and the only other valid flags are -t, -T, -k, -u, -U and -z. The flag -t turns on execution tracing for this function; the flag -T does the same, but turns off tracing for any named (not anonymous) function called from the present one, unless that function also has the -t or -T flag. The -u and -U flags cause the function to be marked for autoloading; -U also causes alias expansion to be suppressed when the function is loaded. See the description of the autoload builtin for details.

Note that the builtin functions provides the same basic capabilities as typeset -f but gives access to a few extra options; autoload gives further additional options for the case typeset -fu and typeset -fU. ๐Ÿงš

  • -h โ€” Hide: only useful for special parameters (those marked <S> in the table in zshparam(1)), and for local parameters with the same name as a special parameter, though harmless for others. A special parameter with this attribute will not retain its special effect when made local. Thus after typeset -h PATH, a function containing typeset PATH will create an ordinary local parameter without the usual behaviour of PATH. Alternatively, the local parameter may itself be given this attribute; hence inside a function typeset -h PATH creates an ordinary local parameter and the special PATH parameter is not altered in any way. It is also possible to create a local parameter using typeset +h special, where the local copy of special will retain its special properties regardless of having the -h attribute. Global special parameters loaded from shell modules (currently those in zsh/mapfile and zsh/parameter) are automatically given the -h attribute to avoid name clashes. ๐Ÿซฃ
  • -H โ€” Hide value: specifies that typeset will not display the value of the parameter when listing parameters; the display for such parameters is always as if the + flag had been given. Use of the parameter is in other respects normal, and the option does not apply if the parameter is specified by name, or by pattern with the -m option. This is on by default for the parameters in the zsh/parameter and zsh/mapfile modules. Note, however, that unlike the -h flag this is also useful for non-special parameters. ๐Ÿ™Š
  • -i [ n ] โ€” use an internal integer representation. If n is nonzero it defines the output arithmetic base, otherwise it is determined by the first assignment. Bases from 2 to 36 inclusive are allowed. ๐Ÿงฎ
  • -E [ n ] โ€” use an internal double-precision floating point representation. On output the variable will be converted to scientific notation. If n is nonzero it defines the number of significant figures to display; the default is ten. ๐Ÿ”ฌ
  • -F [ n ] โ€” use an internal double-precision floating point representation. On output the variable will be converted to fixed-point decimal notation. If n is nonzero it defines the number of digits to display after the decimal point; the default is ten. ๐Ÿ’œ
  • -l โ€” convert the result to lower case whenever the parameter is expanded. The value is not converted when assigned. (yes, lowercase-on-read only, iconic behaviour honestly)
  • -r โ€” the given names are marked readonly. Note that if name is a special parameter, the readonly attribute can be turned on, but cannot then be turned off. ๐Ÿ”’

If the POSIX_BUILTINS option is set, the readonly attribute is more restrictive: unset variables can be marked readonly and cannot then be set; furthermore, the readonly attribute cannot be removed from any variable.

It is still possible to change other attributes of the variable though, some of which like -U or -Z would affect the value. More generally, the readonly attribute should not be relied on as a security mechanism. โš ๏ธ

fr fr bestie, take that last one seriously โ€” readonly is a vibe, not a vault. ๐ŸŽ€

Note that in zsh (like in pdksh but unlike most other shells) it is still possible to create a local variable of the same name as this is considered a different variable (though this variable, too, can be marked readonly). Special variables that have been made readonly retain their value and readonly attribute when made local.

So yeah bestie โ€” you absolutely can make a local with the same name as a special variable, because zsh treats it as a whole different variable ๐Ÿ’… (pdksh gets it, most other shells do NOT). And that local one? Oh, it can be marked readonly too, no loopholes. Meanwhile, if a special variable has already been made readonly, it keeps both its value and its readonly attribute when you make it local. Iconic behavior, honestly.

  • -t โ€” tags the named parameters. Tags have no special meaning to the shell whatsoever โ€” they're just vibes you're attaching. ๐Ÿท๏ธ Heads up tho: this flag means something completely different when used with -f; scroll up for that one.
  • -u โ€” converts the result to upper case whenever the parameter is expanded. The value is not converted when it's assigned โ€” only on expansion, so your stored value stays exactly what you typed. This flag also means something different with -f; see above ๐Ÿ‘€.
  • -x โ€” marks the parameter for automatic export to the environment of subsequently executed commands. ๐Ÿ”ฅ And here's the lore: if the option GLOBAL_EXPORT is set, this implies the option -g, unless +g is also explicitly given. In other words, the parameter is not made local to the enclosing function. This is for compatibility with previous versions of zsh. ๐Ÿซถ

โœจ ulimit โœจ

ulimit [ -HSa ] [ { -bcdfiklmnpqrsTtvwx | -N resource } [ limit ] ... ]

Sets or displays resource limits of the shell and the processes started by the shell, bestie. The value of limit can be:

  • a number in the unit specified below, or
  • the value unlimited, which removes the limit on the resource, or
  • the value hard, which uses the current value of the hard limit on the resource. ๐Ÿ’€

By default, only soft limits are manipulated. If you give the -H flag, use hard limits instead of soft limits. And if you give -S together with -H, it sets both hard and soft limits. ๐ŸŽ€

If no options are used, the file size limit (-f) is assumed.

If limit is omitted, the current value of the specified resources gets printed. When more than one resource value is printed, the limit name and unit is printed before each value, so you actually know what you're looking at. ๐Ÿ“‹

When looping over multiple resources, the shell will abort immediately if it detects a badly formed argument. However โ€” and this is the important bit โ€” if it fails to set a limit for some other reason, it will continue trying to set the remaining limits. No rage-quitting mid-loop for a random failure, but a malformed argument? That's an instant yeet. ๐Ÿšซ

Not all the following resources are supported on all systems. Running ulimit -a will show which are supported. Don't come for me if your kernel doesn't do kqueues, okay? ๐Ÿ˜ญ
  • -a โ€” list all of the current resource limits.
  • -b โ€” socket buffer size in bytes (N.B. not kilobytes โ€” read it again, bestie).
  • -c โ€” 512-byte blocks on the size of core dumps.
  • -d โ€” kilobytes on the size of the data segment.
  • -e โ€” maximum nice value.
  • -f โ€” 512-byte blocks on the size of files written.
  • -i โ€” the number of pending signals.
  • -k โ€” the number of kqueues allocated.
  • -l โ€” kilobytes on the size of locked-in memory.
  • -m โ€” kilobytes on the size of physical memory.
  • -n โ€” open file descriptors.
  • -o โ€” maximum number of POSIX thread library objects.
  • -p โ€” the number of pseudo-terminals.
  • -q โ€” bytes in POSIX message queues.
  • -r โ€” maximum real time priority. On some systems where this is not available, such as NetBSD, this has the same effect as -T, for compatibility with sh. ๐Ÿซ 
  • -s โ€” kilobytes on the size of the stack.
  • -T โ€” the number of simultaneous threads available to the user.
  • -t โ€” CPU seconds to be used.
  • -u โ€” the number of processes available to the user.
  • -v โ€” kilobytes on the size of virtual memory. On some systems this refers to the limit called address space.
  • -w โ€” kilobytes on the size of swapped out memory.
  • -x โ€” the number of locks on files.
  • -y โ€” maximum size of buffers for pipes/fifos.

A resource may also be specified by integer in the form -N resource, where resource corresponds to the integer defined for the resource by the operating system. ๐Ÿง  This is how you set limits for resources the shell knows about that just... don't have an option letter. Such limits will be shown by number in the output of ulimit -a.

And plot twist: the number may alternatively be out of the range of limits compiled into the shell. The shell will try to read or write the limit anyway, and will report an error if this fails. ๐ŸŽฒ So go ahead, try a weird number, live your truth โ€” it might just work.


๐ŸŒธ umask ๐ŸŒธ

umask [ -S ] [ mask ]

The umask is set to mask. mask can be either an octal number or a symbolic value as described in the chmod(1) man page. If mask is omitted, the current value is printed. ๐Ÿ’–

The -S option causes the mask to be printed as a symbolic value. Otherwise, the mask is printed as an octal number.

Note that in the symbolic form, the permissions you specify are those which are to be allowed (not denied) to the users specified. Yes, this is the opposite of what the mask actually does. No, I don't make the rules. ๐Ÿ™ˆ

๐ŸŽ€ unalias ๐ŸŽ€

unalias [ -ams ] name ...

Removes aliases. ๐Ÿ—‘๏ธ This command works the same as unhash -a, except that the -a option removes all regular or global aliases, or โ€” with -s โ€” all suffix aliases: in this case no name arguments may appear.

The options -m (remove by pattern) and -s without -a (remove listed suffix aliases) behave as for unhash -a.

โš ๏ธ Note that the meaning of -a is different between unalias and unhash. Same letter, different plotline, don't get it twisted.

๐Ÿ’œ unfunction ๐Ÿ’œ

unfunction

Same as unhash -f. That's it, that's the whole entry. Short king energy. ๐Ÿ‘‘


๐Ÿฆ‹ unhash ๐Ÿฆ‹

unhash [ -adfms ] name ...

Removes the element named name from an internal hash table. The default is to remove elements from the command hash table. ๐Ÿงน

  • -a โ€” causes unhash to remove regular or global aliases. โš ๏ธ Note: when removing a global alias, the argument must be quoted to prevent it from being expanded before being passed to the command. Yes, before. That's the whole trap.
  • -s โ€” causes unhash to remove suffix aliases.
  • -f โ€” causes unhash to remove shell functions.
  • -d โ€” causes unhash to remove named directories.
  • -m โ€” the arguments are taken as patterns (and they should be quoted โœจ) and all elements of the corresponding hash table with matching names will be removed. Bulk delete, but make it pattern-y.

๐ŸŒˆ unlimit ๐ŸŒˆ

unlimit [ -hs ] resource ...

The resource limit for each resource is set to the hard limit. ๐ŸŽ‰ If the -h flag is given and the shell has appropriate privileges, the hard resource limit for each resource is removed entirely. Bold move.

The resources of the shell process are only changed if the -s flag is given. So without -s, the shell itself? Untouched. ๐Ÿ’…

The unlimit command is not made available by default when the shell starts in a mode emulating another shell. It can be made available with the command zmodload -F zsh/rlimits b:unlimit. There's your unlock code. ๐Ÿ”‘

โญ unset โญ

unset [ -fmv ] name ...

Each named parameter is unset. Local parameters remain local even if unset โ€” they appear unset within scope, but the previous value will still reappear when the scope ends. ๐Ÿ‘ป Spooky but true: unsetting a local doesn't nuke the outer one, it just hides it for a while.

Individual elements of associative array parameters may be unset by using subscript syntax on name, which should be quoted (or the entire command prefixed with noglob) to protect the subscript from filename generation. Seriously, quote it. ๐Ÿซถ

  • -m โ€” the arguments are taken as patterns (they should be quoted โœจ) and all parameters with matching names are unset. โš ๏ธ Note that this cannot be used when unsetting associative array elements, because the subscript would be treated as part of the pattern. Rude, but that's how it is.
  • -v โ€” specifies that name refers to parameters. This is the default behaviour anyway, so it's mostly a vibe-confirmation flag.
  • -f โ€” unset -f is equivalent to unfunction. ๐ŸŽ€

๐Ÿงš unsetopt ๐Ÿงš

unsetopt [ {+|-}options | {+|-}o option_name ] [ name ... ]

Unsets the options for the shell. All options specified either with flags or by name are unset. โœ…

If no arguments are supplied, the names of all options currently unset are printed. ๐Ÿ“œ If the -m flag is given, the arguments are taken as patterns โ€” and bestie, quote them, to preserve them from being interpreted as glob patterns themselves โ€” and all options with names matching those patterns are unset. ๐Ÿ”ฅ


๐Ÿ’ซ vared ๐Ÿ’ซ

See the section Zle Builtins in zshzle(1). That's the whole entry, go read the other page, I'm not doing everything for you ๐Ÿ’… (affectionate).


๐Ÿ‘‘ wait ๐Ÿ‘‘

wait [ job ... ]

Waits for the specified jobs or processes. If job is not given, then all currently active child processes are waited for. โณ

Each job can be either a job specification or the process ID of a job in the job table. The exit status from this command is that of the job waited for. ๐ŸŽฏ

If job represents an unknown job or process ID, a warning is printed (unless the POSIX_BUILTINS option is set) and the exit status is 127.

Here's the cool part: it's possible to wait for recent processes (specified by process ID, not by job) that were running in the background even if the process has already exited. ๐Ÿคฏ Typically the process ID will be recorded by capturing the value of $! immediately after the process has been started. There is a limit on the number of process IDs the shell remembers โ€” it's given by the value of the system configuration parameter CHILD_MAX. When that limit is reached, older process IDs are discarded, least recently started processes first. ๐Ÿ—‘๏ธ

Note there is no protection against process ID wrapping. i.e. if the wait isn't executed soon enough, there's a chance the process you waited for is the wrong one. ๐Ÿ˜ญ A conflict implies both process IDs have been generated by the shell (since other processes aren't recorded) and that the user is potentially interested in both โ€” so this problem is intrinsic to process IDs. It's not a bug, it's just, like, the nature of reality. ๐Ÿ’€

๐Ÿ”ฎ whence ๐Ÿ”ฎ

whence [ -vcwfpamsS ] [ -x num ] name ...

For each name, indicates how it would be interpreted if used as a command name. ๐Ÿ•ต๏ธโ€โ™€๏ธ Detective work, but make it shell.

If name is not an alias, built-in command, external command, shell function, hashed command, or a reserved word, the exit status shall be non-zero, and โ€” if -v, -c, or -w was passed โ€” a message will be written to standard output.

๐Ÿ‘€ Yes, standard output. Not standard error. This is different from other shells that write that message to standard error. So if you're piping, know the difference, bestie.

whence is most useful when name is only the last path component of a command, i.e. it does not include a /. In particular, pattern matching only succeeds if just the non-directory component of the command is passed. ๐Ÿ“

  • -v โ€” produce a more verbose report. ๐Ÿ—ฃ๏ธ
  • -c โ€” print the results in a csh-like format. This takes precedence over -v. โœจ
  • -w โ€” for every name, print name: word, where word is one of alias, builtin, command, function, hashed, reserved or none โ€” depending on whether name is an alias, a built-in command, an external command, a shell function, a command defined with the hash builtin, a reserved word, or justโ€ฆ not recognised at all ๐Ÿ’€. This one takes precedence over -v and -c, so it wins the vibe check.
  • -f โ€” shows the actual contents of a shell function, which normally wouldn't get printed unless you'd used the -c flag. Basically: "let me see inside bestie" ๐Ÿซถ
  • -p โ€” do a path search for name even if it's an alias, reserved word, shell function or builtin. No shortcuts, we're searching for real.
  • -a โ€” search for all occurrences of name across the command path. Normally you just get the first one. And when you combine it with -m, only names that appear in the command hash table get searched, but all occurrences of those names are printed. โœจ
  • -m โ€” the arguments are treated as patterns (so quote your pattern characters, bestie!), and the info gets displayed for every entry in the command hash table matching one of those patterns. The hash table gets refilled first, just in case PATH changed on you.
  • -s โ€” if a pathname contains symlinks, also print the symlink-free pathname. Sneaky links exposed ๐ŸŽ€
  • -S โ€” same as -s, but if the pathname had to be resolved by following multiple symlinks, the intermediate steps get printed too. The symlink resolved at each step might be anywhere in the path, iykyk.
  • -x num โ€” expand tabs when outputting shell functions with the -c option. Same effect as the -x option to the functions builtin.

where

where [ -wpmsS ] [ -x num ] name ...

Equivalent to whence -ca. That's it, that's the whole thing ๐Ÿ’…


which

which [ -wpamsS ] [ -x num ] name ...

Equivalent to whence -c. Short and iconic.


zcompile ๐Ÿงš

zcompile [ -U ] [ -z | -k ] [ -R | -M ] file [ name ... ]
zcompile -ca [ -m ] [ -R | -M ] file [ name ... ]
zcompile -t file [ name ... ]

Okay so this builtin is the "make it go brrr" one โ€” it compiles functions or scripts and stashes the compiled form in a file, and it can also examine files that already contain the compiled form. The whole point? Faster autoloading of functions and sourcing of scripts, because you skip parsing the text every time the files get read. Literally speedrunning your shell startup ๐Ÿ”ฅ

The first form (no -c, no -a, no -t) creates a compiled file. If you only pass the file argument, the output file is named file.zwc and lands in the same directory as file. When the function gets autoloaded, the shell loads the compiled file instead of the normal function file โ€” check the section Autoloading Functions in zshmisc(1) for how autoloaded functions are searched. And .zwc? It stands for zsh word code. Cute, right? ๐Ÿ‘‘

If there's at least one name argument, all the named files get compiled into the output file given as the first argument. If file doesn't end in .zwc, that extension is automatically appended. Files containing multiple compiled functions are called digest files, and they're meant to be used as elements of the FPATH/fpath special array. Very digestive, very demure.

The second form, with -c or -a, writes the compiled definitions for all the named functions into file. For -c, the names must be functions currently defined in the shell โ€” not ones marked for autoloading. Undefined functions marked for autoloading may be written with -a, in which case the fpath is searched and the contents of the definition files for those functions, if found, get compiled into file. If you give both -c and -a, then names of both defined functions and functions marked for autoloading may be given. Either way, functions in files written with -c or -a will be autoloaded as if the KSH_AUTOLOAD option were unset.

๐Ÿ‘€ Why are loaded and not-yet-loaded functions handled with different options? Because some autoloading definition files define multiple functions โ€” including the function with the same name as the file โ€” and then call that function at the end. In those cases zcompile -c does not include the additional functions defined in the file, and any other initialization code in the file is lost. Using zcompile -a captures all that extra info. No cap.

If -m is combined with -c or -a, the names are used as patterns and every function whose name matches one of those patterns gets written. If you give no name at all, the definitions of all functions currently defined or marked as autoloaded get written. Everything, everywhere ๐Ÿซถ

โš ๏ธ Heads up bestie: the second form cannot be used for compiling functions that include redirections as part of the definition rather than inside the body of the function. For example, this one
fn1() { { ... } >~/logfile }

can be compiled, but this one

fn1() { ... } >~/logfile

cannot. If you need that, it's possible to use the first form of zcompile to compile autoloadable functions that include the full function definition instead of just the body. ๐Ÿ’€

The third form, with -t, examines an existing compiled file. With no further arguments, it lists the names of the original files compiled into it. The first line of output shows the version of the shell that compiled the file and how the file will be used (i.e. by reading it directly or by mapping it into memory). With arguments, nothing is output, and the return status is zero if definitions for all names were found in the compiled file, non-zero if the definition for at least one name was not found. โœจ

Other options, because of course there are more:

  • -U โ€” aliases are not expanded when compiling the named files.
  • -R โ€” when the compiled file is read, its contents get copied into the shell's memory rather than memory-mapped (see -M). This happens automatically on systems that don't support memory mapping. When compiling scripts instead of autoloadable functions, it's often desirable to use this option โ€” otherwise the whole file, including the code to define functions which have already been defined, will stay mapped and consequently waste memory. ๐Ÿ“
  • -M โ€” the compiled file is mapped into the shell's memory when read. This is done in a way that multiple instances of the shell running on the same host will share this mapped file. If neither -R nor -M is given, the zcompile builtin decides based on the size of the compiled file.
  • -k
  • -z โ€” these are for when the compiled file contains functions that are meant to be autoloaded. If -z is given, the function will be autoloaded as if KSH_AUTOLOAD is not set, even if it is set at the time the compiled file is read. If -k is given, the function gets loaded as if KSH_AUTOLOAD is set. These options also take precedence over any -k or -z options specified to the autoload builtin. If neither is given, the function loads according to the KSH_AUTOLOAD setting at the time the compiled file is read.

These options may also appear as many times as necessary between the listed names, to specify the loading style of all following functions up to the next -k or -z. Main character energy, honestly.

The created file always contains two versions of the compiled format โ€” one for big-endian machines and one for small-endian machines. The upshot? The compiled file is machine independent, and if it's read or mapped, only one half of the file is actually used (and mapped). Half the file is just vibing there ๐Ÿ’…


zformat

See the section The zsh/zutil Module in zshmodules(1).


zftp

See the section The zsh/zftp Module in zshmodules(1).


zle

See the section Zle Builtins in zshzle(1).


zmodload ๐ŸŒˆ

zmodload [ -dL ] [ -s ] [ ... ]
zmodload -F [ -alLme -P param ] module [ [+-]feature ... ]
zmodload -e [ -A ] [ ... ]
zmodload [ -a [ -bcpf [ -I ] ] ] [ -iL ] ...
zmodload -u [ -abcdpf [ -I ] ] [ -iL ] ...
zmodload -A [ -L ] [ modalias[=module] ... ]
zmodload -R modalias ...

Does all the things related to zsh's loadable modules. โœจ Loading modules while the shell is running (aka dynamical loading) is not available on all operating systems, nor on all installations on a particular operating system โ€” although the zmodload command itself is always available and can be used to manipulate modules built into versions of the shell executable without dynamical loading. So like, sometimes the door is locked but the key is still in your hand, yk?

Without arguments, the names of all currently loaded binary modules get printed. The -L option makes that list come out in the form of a series of zmodload commands. The forms with arguments are:

zmodload [ -is ] name ...
zmodload -u [ -i ] name ...

In the simplest case, zmodload loads a binary module. The module must be in a file whose name is the specified name followed by a standard suffix, usually .so (.sl on HPUX). If the module to be loaded is already loaded, the duplicate module is ignored. If zmodload detects an inconsistency โ€” like an invalid module name or a circular dependency list โ€” the current code block is aborted ๐Ÿ˜ญ. If it's available, the module is loaded if necessary; if it's not available, non-zero status is silently returned. The option -i is accepted for compatibility but has no effect (iconic useless flag behaviour, honestly).

The named module is searched for the same way a command is, using $module_path instead of $path. However, the path search is performed even when the module name contains a / โ€” which it usually does. And there's no way to prevent the path search. Periodt.

So when zmodload loads a module and that module supports features (see below), it tries to enable all the features. If the module loads successfully but not every feature could be enabled, zmodload returns status 2. ๐Ÿ’…

If you pass -s, no error is printed if the module wasnโ€™t available (though other errors that mean the module itself has a problem still print). The return status tells you whether the module was loaded. This is appropriate if the caller considers the module optional. ๐Ÿซถ

With -u, zmodload unloads modules. The same name must be given that was given when the module was loaded, but it is not necessary for the module to exist in the file system. The -i option suppresses the error if the module is already unloaded (or was never loaded). ๐Ÿ˜Œ

Each module has a boot function and a cleanup function. The module will not be loaded if its boot function fails. Similarly, a module can only be unloaded if its cleanup function runs successfully. โœจ


zmodload -F selective feature era ๐ŸŽ€

zmodload -F [ -almLe -P param ] module [ [+-]feature ... ]

zmodload -F gives you way more selective control over the features provided by modules. With no options apart from -F, the module named module is loaded, if it was not already loaded, and the list of features is set to the required state. If no features are specified, the module is loaded, if it was not already loaded, but the state of features is unchanged. ๐Ÿฆ‹

Each feature may be preceded by + to turn the feature on, or - to turn it off; the + is assumed if neither character is present. Any feature not explicitly mentioned is left in its current state; if the module was not previously loaded this means any such features will remain disabled. ๐Ÿ‘‘

The return status is zero if all features were set, 1 if the module failed to load, and 2 if some features could not be set (for example, a parameter couldnโ€™t be added because there was a different parameter of the same name) but the module was loaded. ๐Ÿ’€

tiny status check: 0 = all set, 1 = module failed to load, 2 = module loaded but some features refused to cooperate ๐Ÿ’…

The standard features are builtins, conditions, parameters and math functions; these are indicated by the prefix b:, c: (C: for an infix condition), p: and f:, respectively, followed by the name that the corresponding feature would have in the shell. For example, b:strftime indicates a builtin named strftime and p:EPOCHSECONDS indicates a parameter named EPOCHSECONDS. The module may provide other (abstract) features of its own as indicated by its documentation; these have no prefix. ๐ŸŒˆ

With -l or -L, features provided by the module are listed. ๐Ÿ’–

  • -l alone โ€” a list of features together with their states is shown, one feature per line.
  • -L alone โ€” a zmodload -F command that would cause enabled features of the module to be turned on is shown.
  • -lL โ€” a zmodload -F command that would cause all the features to be set to their current state is shown.

If one of these combinations is given with the option -P param then the parameter param is set to an array of features, either features together with their state or (if -L alone is given) enabled features. ๐ŸŽ€

With the option -L the module name may be omitted; then a list of all enabled features for all modules providing features is printed in the form of zmodload -F commands. If -l is also given, the state of both enabled and disabled features is output in that form. ๐Ÿซถ

A set of features may be provided together with -l or -L and a module name; in that case only the state of those features is considered. Each feature may be preceded by + or - but the character has no effect. If no set of features is provided, all features are considered. โœจ

With -e, the command first tests that the module is loaded; if it is not, status 1 is returned. If the module is loaded, the list of features given as an argument is examined. Any feature given with no prefix is simply tested to see if the module provides it; any feature given with a prefix + or - is tested to see if it is provided and in the given state. If the tests on all features in the list succeed, status 0 is returned, else status 1. ๐Ÿ’…

With -m, each entry in the given list of features is taken as a pattern to be matched against the list of features provided by the module. An initial + or - must be given explicitly. This may not be combined with the -a option as autoloads must be specified explicitly. ๐Ÿฆ‹

With -a, the given list of features is marked for autoload from the specified module, which may not yet be loaded. An optional + may appear before the feature name. If the feature is prefixed with -, any existing autoload is removed. The options -l and -L may be used to list autoloads. Autoloading is specific to individual features; when the module is loaded only the requested feature is enabled. Autoload requests are preserved if the module is subsequently unloaded until an explicit zmodload -Fa module -feature is issued. It is not an error to request an autoload for a feature of a module that is already loaded. ๐ŸŽ€

When the module is loaded each autoload is checked against the features actually provided by the module; if the feature is not provided the autoload request is deleted. A warning message is output; if the module is being loaded to provide a different feature, and that autoload is successful, there is no effect on the status of the current command. If the module is already loaded at the time when zmodload -Fa is run, an error message is printed and status 1 returned. ๐Ÿ˜ญ

zmodload -Fa can be used with the -l, -L, -e and -P options for listing and testing the existence of autoloadable features. In this case -l is ignored if -L is specified. zmodload -FaL with no module name lists autoloads for all modules. ๐Ÿ‘‘

Note that only standard features as described above can be autoloaded; other features require the module to be loaded before enabling. ๐Ÿงš

zmodload -d dependency gossip ๐ŸŒธ

zmodload -d [ -L ] [ name ]
zmodload -d name dep ...
zmodload -ud name [ dep ... ]

The -d option can be used to specify module dependencies. The modules named in the second and subsequent arguments will be loaded before the module named in the first argument. ๐Ÿซถ

With -d and one argument, all dependencies for that module are listed. With -d and no arguments, all module dependencies are listed. This listing is by default in a Makefile-like format. The -L option changes this format to a list of zmodload -d commands. ๐Ÿ’–

If -d and -u are both used, dependencies are removed. If only one argument is given, all dependencies for that module are removed. โœจ


zmodload -ab autoloaded builtins ๐Ÿ“

zmodload -ab [ -L ]
zmodload -ab [ -i ] name [ builtin ... ]
zmodload -ub [ -i ] builtin ...

The -ab option defines autoloaded builtins. It defines the specified builtins. When any of those builtins is called, the module specified in the first argument is loaded and all its features are enabled (for selective control of features use zmodload -F -a as described above). If only the name is given, one builtin is defined, with the same name as the module. -i suppresses the error if the builtin is already defined or autoloaded, but not if another builtin of the same name is already defined. ๐Ÿ’…

With -ab and no arguments, all autoloaded builtins are listed, with the module name (if different) shown in parentheses after the builtin name. The -L option changes this format to a list of zmodload -a commands. ๐ŸŒˆ

If -b is used together with the -u option, it removes builtins previously defined with -ab. This is only possible if the builtin is not yet loaded. -i suppresses the error if the builtin is already removed (or never existed). ๐Ÿ’€

Autoload requests are retained if the module is subsequently unloaded until an explicit zmodload -ub builtin is issued. ๐ŸŽ€


zmodload -ac autoloaded condition codes ๐Ÿฆ‹

zmodload -ac [ -IL ]
zmodload -ac [ -iI ] name [ cond ... ]
zmodload -uc [ -iI ] cond ...

The -ac option is used to define autoloaded condition codes. The cond strings give the names of the conditions defined by the module. The optional -I option is used to define infix condition names. Without this option prefix condition names are defined. โœจ

If given no condition names, all defined names are listed (as a series of zmodload commands if the -L option is given). ๐Ÿ‘‘

The -uc option removes definitions for autoloaded conditions. ๐ŸŒธ


zmodload -ap autoloaded parameters ๐Ÿซถ

zmodload -ap [ -L ]
zmodload -ap [ -i ] name [ parameter ... ]
zmodload -up [ -i ] parameter ...

The -p option is like the -b and -c options, but makes zmodload work on autoloaded parameters instead. ๐Ÿ’–


zmodload -af autoloaded math functions ๐Ÿงš

zmodload -af [ -L ]
zmodload -af [ -i ] name [ function ... ]
zmodload -uf [ -i ] function ...

The -f option is like the -b, -p, and -c options, but makes zmodload work on autoloaded math functions instead. ๐Ÿ’…

  • zmodload -a [ -L ]
  • zmodload -a [ -i ] name [ builtin ... ]
  • zmodload -ua [ -i ] builtin ...

Okay so these three are literally just shorthand โ€” they're equivalent to -ab and -ub. That's it, that's the whole vibe ๐Ÿ’…

  • zmodload -e [ -A ] [ string ... ]

With no arguments, -e lists all the loaded modules for you ๐Ÿ‘‘ and if you also pass -A, it shows the module aliases that correspond to loaded modules too. But if you do pass arguments, nothing gets printed โ€” instead it does a little vibe check: return status 0 if all the strings you gave are names of loaded modules, and 1 if at least one of them isn't ๐Ÿ’€. So it's the perfect "does this thing even exist tho" test for stuff implemented by modules. And heads up: in that case, any aliases get automatically resolved, and the -A flag isn't used. periodt.

  • zmodload -A [ -L ] [ modalias[=module] ... ]

For each argument, if you give both modalias and module, you're defining modalias as an alias for the module module โœจ. If the module modalias ever gets requested later โ€” whether through a call to zmodload or implicitly โ€” the shell will try to load module instead. If you don't give module, it just shows you the definition of modalias. No arguments at all? It lists every defined module alias ๐ŸŽ€. And when it's listing, if you also threw in -L, it prints the definition as a zmodload command so you can recreate the alias โ€” cute and reusable, we love.

The existence of aliases for modules is completely independent of whether the name resolved is actually loaded as a module, no cap. While the alias exists, loading and unloading the module under any alias has exactly the same effect as using the resolved name, and it does not affect the connection between the alias and the resolved name. That connection can only be removed by zmodload -R or by redefining the alias. Chains of aliases (like, where the first resolved name is itself an alias) are valid as long as they're not circular ๐ŸŒ€. And because aliases take the same format as module names, they can totally include path separators โ€” and in that case there's no requirement for any part of the path named to actually exist, because the alias gets resolved first. For example, any/old/alias is always a valid alias. slay.

Dependencies added to aliased modules are actually added to the resolved module, and they stay put even if the alias is removed. It's also valid to create an alias whose name is one of the standard shell modules and which resolves to a different module. However โ€” and this is the catch bestie โ€” if a module has dependencies, you won't be able to use the module name as an alias, because the module will already be marked as a loadable module in its own right ๐Ÿ™ˆ.

Apart from all that, aliases can be used in the zmodload command anywhere module names are required. But they will not show up in lists of loaded modules from a bare zmodload. ikykyk.

  • zmodload -R modalias ...

For each modalias argument that was previously defined as a module alias via zmodload -A, delete the alias ๐Ÿ”ฅ. But if any of them wasn't defined? That's an error, and the rest of the line gets ignored ๐Ÿ’€. So order matters, be careful.

โš ๏ธ Note that zsh makes no distinction between modules that were linked into the shell and modules that are loaded dynamically. In both cases you have to use this builtin command to make the builtins and other things defined by modules available โ€” unless the module is autoloaded on those definitions. And this is true even for systems that don't support dynamic loading of modules fr fr.

๐Ÿงš a whole bunch of "go look at zshmodules(1)" energy

  • zparseopts โ€” See the section The zsh/zutil Module in zshmodules(1). ๐Ÿฆ‹
  • zprof โ€” See the section The zsh/zprof Module in zshmodules(1). ๐ŸŒธ
  • zpty โ€” See the section The zsh/zpty Module in zshmodules(1). ๐ŸŽ€
  • zregexparse โ€” See the section The zsh/zutil Module in zshmodules(1). โญ
  • zsocket โ€” See the section The zsh/net/socket Module in zshmodules(1). ๐Ÿ”Œ
  • zstyle โ€” See the section The zsh/zutil Module in zshmodules(1). ๐Ÿ’…
  • ztcp โ€” See the section The zsh/net/tcp Module in zshmodules(1). ๐ŸŒˆ

And that's the whole page, bestie โ€” you made it to the end of ZSHBUILTINS(1) ๐Ÿซถโœจ This iconic little document is zsh 5.9.2, dated July 12, 2026 โ€” so if you're ever quoting it in a group chat, that's the version and date to cite. Now go forth and use the builtins responsibly ๐Ÿ’– (and remember: the vibes are immaculate, but the exit statuses are real ๐Ÿ˜ญ).

๐Ÿ“ฆ where this page comes from