zshbuiltins (1) Linux Manual Page
NAME
zshbuiltins – zsh built-in commands
SHELL BUILTIN COMMANDS
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.
-
–simple command See the section `Precommand Modifiers’ in zshmisc(1). .file [ arg … ]- Read commands from file and execute them in the current shell environment.
-
If file does not contain a slash, or if
PATH_DIRSis set, the shell looks in the components of$pathto 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 thezcompilebuiltin) 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 … ]- This command does nothing, although normal argument expansions is performed which may have effects on shell parameters. A zero exit status is returned.
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
-gflag is present, define a global alias; global aliases are expanded even if they do not occur in command position.-
If the
-sflag 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 commandps) 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
-mflag 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,-ror-sflags 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
-Lflag 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[ {+|–}RTUXdkmrtWz] [-w] [ name … ]- See the section `Autoloading Functions’ in zshmisc(1) for full details. The
fpathparameter 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
-dis given, searching for the function defaults to$fpath. If a function is loaded by absolute path, any functions loaded from it that are marked forautoloadwithout an absolute path have the load path of the parent function temporarily prepended to$fpath.If the option
-ror-Ris 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$fpathafter the call toautoload. 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 theautoloadcommand rather than at function execution..The flag
-Xmay 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-doption to allow the function search to default to$fpathif it is not in the given location.The flag
+Xattempts 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-mflag 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
-tflag, 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
-Uflag, alias expansion is suppressed when the function is loaded.With the
-wflag, the names are taken as names of files compiled with thezcompilebuiltin, and all functions defined in them are marked for autoloading.The flags
-zand-kmark the function to be autoloaded using the zsh or ksh style, as if the optionKSH_AUTOLOADwere unset or were set, respectively. The flags override the setting of the option at the time the function is loaded.Note that the
autoloadcommand makes no attempt to ensure the shell options set during the loading or execution of the file have any particular value. For this, theemulatecommand can be used:-
emulate zsh -c 'autoload -Uzfunc'
arranges that when func is loaded the shell is in native
zshemulation, and this emulation is also applied when func is run.Some of the functions of
autoloadare also provided byfunctions -uorfunctions -U, butautoloadis a more comprehensive interface.
-
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 ]- Exit from an enclosing
for,while,until,selectorrepeatloop. If an arithmetic expression n is specified, then break n levels instead of just one. builtinname [ args … ]- Executes the builtin name, with the given args.
bye- Same as
exit. cap- See the section `The zsh/cap Module’ in zshmodules(1).
-
cd[-qsLP] [ arg ] -
cd[-qsLP] old new -
cd[-qsLP] {+|–}n Change the current directory. In the first form, change the current directory to arg, or to the value of$HOMEif arg is not specified. If arg is `–‘, change to the previous directory.-
Otherwise, if arg begins with a slash, attempt to change to the directory given by arg.
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 parametercdpath. If it does not, first attempt to change to the directory arg under the current directory, and if that fails butcdpathis set and contains at least one element attempt to change to the directory arg under each component ofcdpathin turn until successful. If `.‘ occurs incdpath, thencdpathis searched strictly in order so that `.‘ is only tried at the appropriate point.The order of testing
cdpathis modified if the optionPOSIX_CDis set, as described in the documentation for the option.If no directory is found, the option
CDABLE_VARSis 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.The second form of
cdsubstitutes the string new for the string old in the name of the current directory, and tries to change to this new directory.The third form of
cdextracts 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 thedirscommand, starting with zero. An argument of the form `–n‘ counts from the right. If thePUSHD_MINUSoption is set, the meanings of `+‘ and `–‘ in this context are swapped. If thePOSIX_CDoption is set, this form ofcdis not recognised and will be interpreted as the first form.If the
-q(quiet) option is specified, the hook functionchpwdand the functions in the arraychpwd_functionsare not called. This is useful for calls tocdthat do not change the environment seen by an interactive user.If the
-soption is specified,cdrefuses to change the current directory if the given pathname contains symlinks. If the-Poption is given or theCHASE_LINKSoption is set, symbolic links are resolved to their true values. If the-Loption is given symbolic links are retained in the directory (and not resolved) regardless of the state of theCHASE_LINKSoption.
chdir- Same as
cd. clone- See the section `The zsh/clone Module’ in zshmodules(1).
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_BUILTINSoption is set, builtins will also be executed but certain special properties of them are suppressed. The-pflag causes a default path to be searched instead of that in$path. With the-vflag,commandis similar towhenceand with-V, it is equivalent towhence -v.-
See also the section `Precommand Modifiers’ in zshmisc(1).
comparguments- See the section `The zsh/computil Module’ in zshmodules(1).
compcall- See the section `The zsh/compctl Module’ in zshmodules(1).
compctl- See the section `The zsh/compctl Module’ in zshmodules(1).
compdescribe- See the section `The zsh/computil Module’ in zshmodules(1).
compfiles- See the section `The zsh/computil Module’ in zshmodules(1).
compgroups- See the section `The zsh/computil Module’ in zshmodules(1).
compquote- See the section `The zsh/computil Module’ in zshmodules(1).
comptags- See the section `The zsh/computil Module’ in zshmodules(1).
comptry- See the section `The zsh/computil Module’ in zshmodules(1).
compvalues- See the section `The zsh/computil Module’ in zshmodules(1).
continue[ n ]- Resume the next iteration of the enclosing
for,while,until,selectorrepeatloop. If an arithmetic expression n is specified, break out of n-1 loops and resume at the nth enclosing loop. declare- Same as
typeset. -
dirs[-c] [ arg … ] -
dirs[-lpv] With no arguments, print the contents of the directory stack. Directories are added to this stack with thepushdcommand, and removed with thecdorpopdcommands. If arguments are specified, load them onto the directory stack, replacing anything that was there, and push the current directory onto the stack.-
-
-cclear the directory stack. -l- print directory names in full instead of using 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[-afmprs] name …- Temporarily disable the named hash table elements or patterns. The default is to disable builtin commands. This allows you to use an external command with the same name as a builtin command. The
-aoption causesdisableto act on regular or global aliases. The-soption causesdisableto act on suffix aliases. The-foption causesdisableto act on shell functions. The-roptions causesdisableto act on reserved words. Without arguments all disabled hash table elements from the corresponding hash table are printed. With the-mflag 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 theenablecommand.-
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_GLOBandSH_GLOBare never enabled, regardless of the setting here. For example, ifEXTENDED_GLOBis 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 settingSH_GLOBhas a wider effect than merely disabling patterns as certain expressions, in particular those involving parentheses, are parsed differently.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 withKSH_GLOB. ‘*’- The pattern character
*wherever it occurs, including recursive globbing and when preceding a parenthesis withKSH_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_GLOBwhere 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[ 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.-
If the jobs are currently stopped and the
AUTO_CONTINUEoption 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 theAUTO_CONTINUEoption.
echo[-neE] [ arg … ]- Write each arg on the standard output, with a space separating each one. If the
-nflag is not present, print a newline at the end.echorecognizes the following escape sequences:-
- bell character
- backspace
