Shell Builtin 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 Precommand Modifiers.
. 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.zwcis 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:% 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 functionsIf 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
*.psto be expanded togv -- *.ps. As alias expansion is carried out earlier than globbing, the*.pswill 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, including common problems, see Aliasing.
autoload [ {+|-}RTUXdkmrtWz ] [ -w ] [ name … ]
See Autoloading Functions 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 -Uz func'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 -u ``orfunctions -U``, but`` autoload`` is a more comprehensive interface.
bg [ job … ]
job … &
Put each specified job in the background, or the current job if none is specified.
bindkey
See Zle Builtins.
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.
builtin name [ args … ]
Executes the builtin name, with the given args.
bye
Same as
exit.
cap
See The zsh/cap Module.
cd [ -qsLP ] [ arg ]
cd [ -qsLP ] old new
cd [ -qsLP ] {+|-}:var: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 zsh/clone Module.
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 Precommand Modifiers.
comparguments
See The zsh/computil Module.
compcall
See The zsh/compctl Module.
compctl
See The zsh/compctl Module.
compdescribe
See The zsh/computil Module.
compfiles
See The zsh/computil Module.
compgroups
See The zsh/computil Module.
compquote
See The zsh/computil Module.
comptags
See The zsh/computil Module.
comptry
See The zsh/computil Module.
compvalues
See The zsh/computil Module.
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 the
pushdcommand, 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.
-lprint directory names in full instead of using
~expressions (see Filename Expansion).
-pprint directory entries one per line.
-vnumber 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 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 ifdisable -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 (usesetopt NO_BARE_GLOB_QUALto 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 [ -a | 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. With
-a, disown all jobs.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:
\abell character
\bbackspace
\csuppress subsequent characters and final newline
\eescape
\fform feed
\nlinefeed (newline)
\rcarriage return
\thorizontal tab
\vvertical tab
\\backslash
\0NNNcharacter code in octal
\xNNcharacter code in hexadecimal
\uNNNNunicode character code in hexadecimal
\UNNNNNNNNunicode character code in hexadecimal
The
-Eflag, or theBSD_ECHOoption, can be used to disable these escape sequences. In the latter case,-eflag can be used to enable them.Note that for standards compliance a double dash does not terminate option processing; instead, it is printed directly. However, a single dash does terminate option processing, so the first dash, possibly following options, is not printed, but everything following it is printed as an argument. The single dash behaviour is different from other shells. For a more portable way of printing text, see
printf, and for a more controllable way of printing text within zsh, see
echotc
See The zsh/termcap Module.
echoti
See The zsh/terminfo Module.
emulate [ -lLR ] [ {zsh|sh|ksh|csh} [ flags … ] ]
Without any argument print current emulation mode.
With single argument set up zsh options to emulate the specified shell as much as possible. csh will never be fully emulated. If the argument is not one of the shells listed above,
zshwill be used as a default; more precisely, the tests performed on the argument are the same as those used to determine the emulation at startup based on the shell name, see Compatibility. In addition to setting shell options, the command also restores the pristine state of pattern enables, as if all patterns had been enabled usingenable -p.If the
emulatecommand occurs inside a function that has been marked for execution tracing withfunctions -tthen thextraceoption will be turned on regardless of emulation mode or other options. Note that code executed inside the function by the.,source, orevalcommands is not considered to be running directly from the function, hence does not provoke this behaviour.If the
-Rswitch is given, all settable options are reset to their default value corresponding to the specified emulation mode, except for certain options describing the interactive environment; otherwise, only those options likely to cause portability problems in scripts and functions are altered. If the-Lswitch is given, the optionsLOCAL_OPTIONS,LOCAL_PATTERNSandLOCAL_TRAPSwill be set as well, causing the effects of theemulatecommand and anysetopt,disable -porenable -p, andtrapcommands to be local to the immediately surrounding shell function, if any; normally these options are turned off in all emulation modes exceptksh. The-Lswitch is mutually exclusive with the use of-cin flags.If there is a single argument and the
-lswitch is given, the options that would be set or unset (the latter indicated with the prefixno) are listed.-lcan be combined with-Lor-Rand the list will be modified in the appropriate way. Note the list does not depend on the current setting of options, i.e. it includes all options that may in principle change, not just those that would actually change.The flags may be any of the invocation-time flags described in Invocation, except that
-o EMACSand-o VImay not be used.If
-carg appears in flags, arg is evaluated while the requested emulation is temporarily in effect. In this case the emulation mode and all options are restored to their previous values beforeemulatereturns. The-Rswitch may precede the name of the shell to emulate; note this has a meaning distinct from including-Rin flags.Use of
-cenables `sticky’ emulation mode for functions defined within the evaluated expression: the emulation mode is associated thereafter with the function so that whenever the function is executed the emulation (respecting the-Rswitch, 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 within anemulateshell-cexpression or within another function with the same sticky emulation, entry and exit from the function do not cause options to be altered (except due to standard processing such as theLOCAL_OPTIONSoption). This also applies to functions marked for autoload within the sticky emulation; the appropriate set of options will be applied at the point the function is loaded as well as when it is run.For example:
emulate sh -c 'fni() { setopt cshnullglob; } fno() { fni; }' fnoThe two functions
fniandfnoare defined with stickyshemulation.fnois then executed, causing options associated with emulations to be set to their values insh.fnothen callsfni; becausefniis also marked for stickyshemulation, no option changes take place on entry to or exit from it. Hence the optioncshnullglob, turned off byshemulation, will be turned on withinfniand remain on return tofno. On exit fromfno, the emulation mode and all options will be restored to the state they were in before entry to the temporary emulation.The documentation above is typically sufficient for the intended purpose of executing code designed for other shells in a suitable environment. More detailed rules follow.
The sticky emulation environment provided by
emulateshell-cis identical to that provided by entry to a function marked for sticky emulation as a consequence of being defined in such an environment. Hence, for example, the sticky emulation is inherited by subfunctions defined within functions with sticky emulation.No change of options takes place on entry to or exit from functions that are not marked for sticky emulation, other than those that would normally take place, even if those functions are called within sticky emulation.
No special handling is provided for functions marked for
autoloadnor for functions present in wordcode created by thezcompilecommand.The presence or absence of the
-Rswitch toemulatecorresponds to different sticky emulation modes, so for exampleemulate sh -c,emulate -R sh -candemulate csh -care treated as three distinct sticky emulations.Difference in shell options supplied in addition to the basic emulation also mean the sticky emulations are different, so for example
emulate zsh -candemulate zsh -o cbases -care treated as distinct sticky emulations.
enable [ -afmprs ] name …
Enable the named hash table elements, presumably disabled earlier with
disable. The default is to enable builtin commands. The-aoption causesenableto act on regular or global aliases. The-soption causesenableto act on suffix aliases. The-foption causesenableto act on shell functions. The-roption causesenableto act on reserved words. Without arguments all enabled hash table elements from the corresponding hash table are printed. With the-mflag the arguments are taken as patterns (should be quoted) and all hash table elements from the corresponding hash table matching these patterns are enabled. Enabled objects can be disabled with thedisablebuiltin command.
enable -preenables patterns disabled withdisable -p. Note that it does not override globbing options; for example,enable -p "~" ``does not cause the pattern character~`` to be active unless theEXTENDED_GLOBoption is also set. To enable all possible patterns (so that they may be individually disabled withdisable -p), usesetopt EXTENDED_GLOB KSH_GLOB NO_SH_GLOB.
eval [ arg … ]
Read the arguments as input to the shell and execute 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. are an empty string or whitespace) the return status is zero.
exec [ -cl ] [ -a argv0 ] [ command [ arg … ] ]
Replace the current shell with command rather than forking. If command is a shell builtin command or a shell function, the shell executes it, and exits when the command is complete.
With
-cclear the environment; with-lprepend-to theargv[0]string of the command executed (to simulate a login shell); with-aargv0 set theargv[0]string of the command executed. See Precommand Modifiers.If the option
POSIX_BUILTINSis set, command is never interpreted as a shell builtin command or shell function. This means further precommand modifiers such asbuiltinandnoglobare also not interpreted within the shell. Hence command is always found by searching the command path.If command is omitted but any redirections are specified, then the redirections will take effect in the current shell.
exit [ n ]
Exit the shell with the exit status specified by an arithmetic expression n; if none is specified, use the exit status from the last command executed. .. index:: single: IGNORE_EOF, use of; Program
An EOF condition will also cause the shell to exit, unless the
IGNORE_EOFoption is set.See notes at the end of Signals for some possibly unexpected interactions of the
exitcommand with jobs.
export [ name[=value] … ]
The specified names are marked for automatic export to the environment of subsequently executed commands. Equivalent to
typeset -gx. If a parameter specified does not already exist, it is created in the global scope.
false [ arg … ]
Do nothing and return an exit status of 1.
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 ]
The
fccommand controls the interactive history mechanism. Note that reading and writing of history options is only performed if the shell is interactive. Usually this is detected automatically, but it can be forced by setting theinteractiveoption when starting the shell.The first two forms of this command select a range of events from first to last from the history list. The arguments first and last may be specified as a number or as a string. A negative number is used as an offset to the current history event number. A string specifies the most recent event beginning with the given string. All substitutions old
=new, if any, are then performed on the text of the events.The range of events selected by numbers can be narrowed further by the following flags.
-Irestricts to only internal events (not from
$HISTFILE)-Lrestricts to only local events (not from other shells, see
SHARE_HISTORYin zshoptions – note that$HISTFILEis considered local when read at startup)-mtakes the first argument as a pattern (which should be quoted) and only the history events matching this pattern are considered
If first is not specified, it will be set to -1 (the most recent event), or to -16 if the
-lflag is given. If last is not specified, it will be set to first, or to -1 if the-lflag is given. However, if the current event has added entries to the history withprint -sorfc -R, then the default last for-lincludes all new history entries since the current event began.When the
-lflag is given, the resulting events are listed on standard output. Otherwise the editor program specified by-eename is invoked on a file containing these history events. If-eis not given, the value of the parameterFCEDITis used; if that is not set the value of the parameterEDITORis used; if that is not set a builtin default, usuallyviis used. If ename is-, no editor is invoked. When editing is complete, the edited command is executed.The flag
-sis equivalent to-e -. The flag-rreverses the order of the events and the flag-nsuppresses event numbers when listing.Also when listing,
-dprints timestamps for each event
-fprints full time-date stamps in the US MM
/DD/YY hh:mm format-Eprints full time-date stamps in the European dd
.mm.yyyy hh:mm format-iprints full time-date stamps in ISO8601 yyyy
-mm-dd hh:mm format-tfmtprints time and date stamps in the given format; fmt is formatted with the strftime function with the zsh extensions described for the
%D{string}prompt format in Simple Prompt Escapes. The resulting formatted string must be no more than 256 characters or will not be printed-Dprints elapsed times; may be combined with one of the options above
fc -ppushes the current history list onto a stack and switches to a new history list. If the-aoption is also specified, this history list will be automatically popped when the current function scope is exited, which is a much better solution than creating a trap function to callfc -Pmanually. If no arguments are specified, the history list is left empty,$HISTFILEis unset, and$HISTSIZE&$SAVEHISTare set to their default values. If one argument is given,$HISTFILEis set to that filename,$HISTSIZE&$SAVEHISTare left unchanged, and the history file is read in (if it exists) to initialize the new list. If a second argument is specified,$HISTSIZE&$SAVEHISTare instead set to the single specified numeric value. Finally, if a third argument is specified,$SAVEHISTis set to a separate value from$HISTSIZE. You are free to change these environment values for the new history list however you desire in order to manipulate the new history list.
fc -Ppops the history list back to an older list saved byfc -p. The current list is saved to its$HISTFILEbefore it is destroyed (assuming that$HISTFILEand$SAVEHISTare set appropriately, of course). The values of$HISTFILE,$HISTSIZE, and$SAVEHISTare restored to the values they had whenfc -pwas called. Note that this restoration can conflict with making these variables “local”, so your best bet is to avoid local declarations for these variables in functions that usefc -p. The one other guaranteed-safe combination is declaring these variables to be local at the top of your function and using the automatic option (-a) withfc -p. Finally, note that it is legal to manually pop a push marked for automatic popping if you need to do so before the function exits.
fc -Rreads the history from the given file,fc -Wwrites the history out to the given file, andfc -Aappends the history out to the given file. If no filename is specified, the$HISTFILEis assumed. If the-Ioption is added to-R, only those events that are not already contained within the internal history list are added. If the-Ioption is added to-Aor-W, only those events that are new since last incremental append/write to the history file are appended/written. In any case, the created file will have no more than$SAVEHISTentries.
fg [ job … ]
job …
Bring each specified job in turn to the foreground. If no job is specified, resume the current job.
float [ {+|-}Hghlprtux ] [ {+|-}EFLRZ [ n ] ] [ name[=value] … ]
Equivalent to
typeset -E, except that options irrelevant to floating point numbers are not permitted.
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,-Mand-Woptions. Forfunctions -uandfunctions -U, seeautoload, which provides additional options. Forfunctions -tandfunctions -T, seetypeset -f.The
-xoption indicates that any functions output will have each leading tab for indentation, added by the shell to show syntactic structure, expanded to the given number num of spaces. num can also be 0 to suppress all indentation.The
-Woption turns on the optionWARN_NESTED_VARfor 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-Wattribute.The
-coption causes oldfn to be copied to newfn. The copy is efficiently handled internally by reference counting. If oldfn was marked for autoload it is first loaded and if this 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 callnewfn, thereby installing a modified version of the function.The ``-M``:emphasis:` and ``+M`:emphasis:` flags` .. index:: single: defining mathematical functions; Command
Use of the
-Moption may not be combined with any of the options handled bytypeset -f.
functions -Mmathfn defines mathfn as the name of a mathematical function recognised in all forms of arithmetical expressions; see Arithmetic Evaluation. 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 that there is no upper limit.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 remains the name used in arithmetical expressions. The name of the function in
$0is mathfn (not shellfn as would usually be the case), provided the optionFUNCTION_ARGZEROis 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
$((…)), but also includes arithmetical expressions evaluated in any other way, including by theletbuiltin, by((…))statements, and even by thereturnbuiltin and by array subscripts. Therefore, care must be taken not to use syntactical constructs that perform arithmetic evaluation after evaluating what is 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
0because of thereturn.Commenting the
returnout 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 would happen to be zero (numerically):# WRONG zmath_cube() { (( $1 * $1 * $1 )) } functions -M cube 1 1 zmath_cube print $(( cube(0) ))Instead, the
truebuiltin can be used:# RIGHT zmath_cube() { (( $1 * $1 * $1 )) true } functions -M cube 1 1 zmath_cube print $(( cube(3) ))If the additional option
-sis given tofunctions -M, the argument to the function is a single string: anything between the opening and matching closing parenthesis is passed to the function as a single argument, even if it includes commas or white space. The minimum and maximum argument specifiers must therefore be 1 if given. An empty argument list is passed as a zero-length string. Thus, the following string function takes a single argument, including the commas, and prints 11:stringfn() { (( $#1 )); true } functions -Ms stringfn print $(( stringfn(foo,bar,rod) ))
functions -Mwith no arguments lists all such user-defined functions in the same form as a definition. With the additional option-mand a list of arguments, all functions whose mathfn matches one of the pattern arguments are listed.
function +Mremoves the list of mathematical functions; with the additional option-mthe arguments are treated as patterns and all functions whose mathfn matches the pattern are removed. Note that the shell function implementing the behaviour is not removed (regardless of whether its name coincides with mathfn).
getcap
See The zsh/cap Module.
getln [ -AclneE ] name …
Read the top value from the buffer stack and put it in the shell parameter name. Equivalent to
read -zr.
getopts [ -p ] optstring name [ arg … ]
Checks the args for legal options. If the args are omitted, the positional parameters are used. A valid option argument begins with a
+or a-. An argument not beginning with a+or a-, or the argument--, ends the options. Note that a single-is not considered a valid option argument. optstring contains the letters thatgetoptsrecognizes. If a letter is followed by a:, that option requires an argument. The argument may appear either immediately following the option in the same word, or in the next word.Each time it is invoked,
getoptsplaces the option letter it finds in the shell parameter name, prepended with a+when arg begins with a+. The index of the next arg is stored inOPTIND. The option argument, if any, is stored inOPTARG. .. index:: single: OPTIND, use of; VariableWhen the terminator
--is encountered,OPTINDis incremented such that it can beshifted away with the options. This is not true of other non-option arguments, including a single-.The first option to be examined may be changed by explicitly assigning to
OPTIND.OPTINDhas an initial value of1, and is normally set to1upon entry to a shell function and restored upon exit.OPTARGis not reset and retains its value from the most recent call togetopts. If either ofOPTINDorOPTARGis explicitly unset, it remains unset, and the index or option argument is not stored. The option itself is still stored in name in this case.A leading
:in optstring causesgetoptsto store the letter of any invalid option inOPTARG, and to set name to?for an unknown option and to:when a required argument is missing. Otherwise,getoptssets name to?and prints an error message when an option is invalid. The exit status is nonzero when there are no more options.When either the
POSIX_BUILTINSoption is enabled or the-poption is given togetoptsitself,getoptsbehaves in a more POSIX-compatible manner. Specifically, handling of+-prefixed options is disabled (they are treated as non-options) and the value ofOPTINDis calculated differently. Additionally, withPOSIX_BUILTINS(but not with-p), the value ofOPTINDis not kept local to the calling function.
hash [ -Ldfmrv ] [ name[=value] ] …
hashcan be used to directly modify the contents of the command hash table, and the named directory hash table. Normally one would modify these tables by modifying one’sPATH(for the command hash table) or by creating appropriate shell parameters (for the named directory hash table). The choice of hash table to work on is determined by the-doption; without the option the command hash table is used, and with the option the named directory hash table is used.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 explicit use of thehashcommand. Such a command is always found by direct look up in the file system.Given no arguments, and neither the
-ror-foptions, the selected hash table will be listed in full.The
-roption causes the selected hash table to be emptied. It will be subsequently rebuilt in the normal fashion. The-foption causes the selected hash table to be fully rebuilt immediately. For the command hash table this hashes all (and only) the absolute directories in thePATH, and for the named directory hash table this adds all users’ home directories. These two options cannot be used with any arguments. Both options remove any explicitly-added elements.The
-moption causes the arguments to be taken as patterns (which should be quoted) and the elements of the hash table matching those patterns are printed. This is the only way to display a limited selection of hash table elements.For each name with a corresponding value, put name in the selected hash table, associating it with the pathname value. In the command hash table, this means that 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, this means that value may be referred to as
~name.For each name with no corresponding value, attempt to add name to the hash table, checking what the appropriate
valueis in the normal manner for that hash table. If an appropriatevaluecan’t be found, then the hash table will be unchanged.The
-voption causes hash table entries to be listed as they are added by explicit specification. If has no effect if used with-f.If the
-Lflag is present, then each hash table entry is printed in the form of a call to hash.
history
Same as
fc -l.
integer [ {+|-}Hghlprtux ] [ {+|-}LRZi [ n ] ] [ name[=value] … ]
Equivalent to
typeset -i, except that options irrelevant to integers are not permitted.
jobs [ -dlprs ] [ job … ]
jobs -Z string
Lists information about each given job, or all jobs if job is omitted. The
-lflag lists process IDs, and the-pflag lists process groups. If the-rflag is specified only running jobs will be listed and if the-sflag is given only stopped jobs are shown. If the-dflag is given, the directory from which the job was started (which may not be the current directory of the job) will also be shown.The
-Zoption replaces the shell’s argument and environment space with the given string, truncated if necessary to fit. This will normally be visible inps(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 or within the
(…)construct. However, a snapshot of the job state at that point is taken, so it is still possible to use thejobsbuiltin, or any parameter providing job information. This gives information about the state of jobs at the point the subshell was created. If background processes are created within the subshell, then instead information about those processes is provided.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 [ -s signal_name | -n signal_number | -sig ] [ -q value ] job …
kill -l [ sig … ]
kill -L
Sends either
SIGTERMor the specified signal to the given jobs or processes. Signals are given by number or by names, with or without theSIGprefix. If the signal being sent is notKILLorCONT, then the job will be sent aCONTsignal if it is stopped. The argument job can be the process ID of a job not in the job list. In the second form,kill -l, if sig is not specified the signal names are listed. Otherwise, for each sig that is a name, the corresponding signal number is listed. For each sig that is 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 is printed. The final form with-Llists each signal name with its corresponding number.On some systems, alternative signal names are allowed for a few signals. Typical examples are
SIGCHLDandSIGCLDorSIGPOLLandSIGIO, assuming they correspond to the same signal number.kill -l ``will only list the preferred form, howeverkill -l`` alt will show if the alternative form corresponds to a signal number. For example, under Linuxkill -l IOandkill -l POLLboth output 29, hencekill -IOandkill -POLLhave 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
-qoption allows an integer value to be sent with the signal on systems that supportsigqueue().
let arg …
Evaluate each arg as an arithmetic expression. See Arithmetic Evaluation for a description of arithmetic expressions. The exit status is 0 if the value of the last expression is nonzero, 1 if it is zero, and 2 if an error occurred.
limit [ -hs ] [ resource [ limit ] ] …
Set or display resource limits. Unless the
-sflag is given, the limit applies only the children of the shell. If-sis given without other arguments, the resource limits of the current shell is set to the previously set resource limits of the children.If limit is not specified, print the current limit placed on resource, otherwise set the limit to the specified value. If the
-hflag is given, use hard limits instead of soft limits. If no resource is given, print all limits.When looping over multiple resources, the shell will abort immediately if it detects a badly formed argument. However, if it fails to set a limit for some other reason it will continue trying to set the remaining limits.
resource can be one of:
addressspaceMaximum amount of address space used.
aiomemorylockedMaximum amount of memory locked in RAM for AIO operations.
aiooperationsMaximum number of AIO operations.
cachedthreadsMaximum number of cached threads.
coredumpsizeMaximum size of a core dump.
cputimeMaximum CPU seconds per process.
datasizeMaximum data size (including stack) for each process.
descriptorsMaximum value for a file descriptor.
filesizeLargest single file allowed.
kqueuesMaximum number of kqueues allocated.
maxfilelocksMaximum number of file locks.
maxprocMaximum number of processes.
maxpthreadsMaximum number of threads per process.
memorylockedMaximum amount of memory locked in RAM.
memoryuseMaximum resident set size.
msgqueueMaximum number of bytes in POSIX message queues.
niceMaximum nice value.
pipebufMaximum size of buffers for pipes/fifos.
posixlocksMaximum number of POSIX locks per user.
pseudoterminalsMaximum number of pseudo-terminals.
residentMaximum resident set size.
rt_priorityMaximum real-time priority.
rt_timeMaximum CPU time without a blocking system call.
sigpendingMaximum number of pending signals.
sockbufsizeMaximum size of all socket buffers.
stacksizeMaximum stack size for each process.
swapsizeMaximum amount of swap used.
umtxpMaximum number of POSIX thread library objects.
vmemorysizeMaximum amount of virtual memory.
vnodemonitorsMaximum number of open vnode monitors.
Which of these resource limits are available depends on the system. resource can be abbreviated to any unambiguous prefix. It can also be an integer, which corresponds to the integer defined for the resource by the operating system.
If argument corresponds to a number which is out of the range of the resources configured into the shell, the shell will try to read or write the limit anyway, and will report an error if this fails. As the shell does not store such resources internally, an attempt to set the limit will fail unless the
-soption is present.limit is a number, with an optional scaling factor, as follows:
- n
hhours
- n
kkilobytes (default)
- n
mmegabytes or minutes
- n
ggigabytes
- [mm
:]:var:ssminutes and seconds
The
limitcommand is not made available by default when the shell starts in a mode emulating another shell. It can be made available with the commandzmodload -F zsh/rlimits b:limit.
local [ {+|-}AHUahlprtux ] [ {+|-}EFLRZi [ n ] ] [ name[=value] … ]
Same as
typeset, except that the options-g, and-fare not permitted. In this case the-xoption does not force the use of-g, i.e. exported variables will be local to functions.
logout [ n ]
Same as
exit, except that it only works in a login shell.
noglob simple command
See Precommand Modifiers.
popd [ -q ] [ {+|-}:var:n ]
Remove an entry from the directory stack, and perform a
cdto the new top directory. With no argument, the current top entry is removed. 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. .. index:: single: PUSHD_MINUS, use of; ProgramIf the
PUSHD_MINUSoption is set, the meanings of+and-in this context are swapped.If the
-q(quiet) option is specified, the hook functionchpwdand the functions in the array$chpwd_functionsare not called, and the new directory stack is not printed. This is useful for calls topopdthat do not change the environment seen by an interactive user.
print [ -abcDilmnNoOpPrsSz ] [ -u n ] [ -f format ] [ -C cols ]
[
-vname ] [-xXtabstop ] [-R[-en]] [ arg … ]With the
-foption the arguments are printed as described byprintf. With no flags or with the flag-, the arguments are printed on the standard output as described byecho, with the following differences: 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), and\Eis a synonym for\e. Finally, if not in an escape sequence,\escapes the following character and is not printed.
-aPrint arguments with the column incrementing first. Only useful with the
-cand-Coptions.
-bRecognize all the escape sequences defined for the
bindkeycommand, see Zle Builtins.
-cPrint the arguments in columns. Unless
-ais also given, arguments are printed with the row incrementing first.
-CcolsPrint the arguments in cols columns. Unless
-ais also given, arguments are printed with the row incrementing first.
-DTreat the arguments as paths, replacing directory prefixes with
~expressions corresponding to directory names, as appropriate.
-iIf given together with
-oor-O, sorting is performed case-independently.
-lPrint the arguments separated by newlines instead of spaces. Note: if the list of arguments is empty,
print -lwill still output one empty line. To print a possibly-empty list of arguments one per line, useprint -C1, as inprint -rC1 -- "$list[@]".
-mTake 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.
-nDo not add a newline to the output.
-NPrint the arguments separated and terminated by nulls. Again,
print -rNC1 -- "$list[@]"is a canonical way to print an arbitrary list as null-delimited records.
-oPrint the arguments sorted in ascending order.
-OPrint the arguments sorted in descending order.
-pPrint the arguments to the input of the coprocess.
-PPerform prompt expansion (see Expansion of Prompt Sequences). In combination with
-f, prompt escape sequences are parsed only within interpolated arguments, not within the format string.
-rIgnore the escape conventions of
echo.
-REmulate the BSD
echocommand, which does not process escape sequences unless the-eflag is given. The-nflag suppresses the trailing newline. Only the-eand-nflags are recognized after-R; all other arguments and options are printed.
-sPlace the results in the history list instead of on the standard output. Each argument to the
-SPlace 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_WORDSoption active.
-unPrint the arguments to file descriptor n.
-vnameStore the printed arguments as the value of the parameter name.
-xtab-stopExpand 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
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
MULTIBYTEis in effect. This option is ignored if other formatting options are in effect, namely column alignment orprintfstyle, or if output is to a special location such as shell history or the command line editor.
-Xtab-stopThis 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.
-zPush the arguments onto the editing buffer stack, separated by spaces.
If any of
-m,-oor-Oare used in combination with-fand there are no arguments (after the removal process in the case of-m) then nothing is printed.
printf [ -v name ] format [ arg … ]
Print the arguments according to the format specification. Formatting rules are the same as used in C. The same escape sequences as for
echoare recognised in the format. All C conversion specifications ending in one ofcsdiouxXeEfgGnare handled. In addition to this,%bcan be used instead of%sto cause escape sequences in the argument to be recognised and%qcan be used to quote the argument in such a way that allows it to be reused as shell input. 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 Arithmetic Evaluation 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.If arguments remain unused after formatting, the format string is reused until all arguments have been consumed. With the
-roption. 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
-voption 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 [ -qsLP ] [ arg ]
pushd [ -qsLP ] old new
pushd [ -qsLP ] {+|-}:var:n
Change the current directory, and push the old current directory onto the directory stack. 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
$HOMEif thePUSHD_TO_HOMEoption is set or if there is only one entry on the stack. Otherwise, arg is interpreted as it would be bycd. The meaning of old and new in the second form is also the same as forcd.The third form of
pushdchanges 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 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 the
-q(quiet) option is specified, the hook functionchpwdand the functions in the array$chpwd_functionsare not called, and the new directory stack is not printed. This is useful for calls topushdthat do not change the environment seen by an interactive user.If the option
-qis not specified and the shell optionPUSHD_SILENTis not set, the directory stack will be printed after apushdis performed.The options
-s,-Land-Phave the same meanings as for thecdbuiltin.
pushln [ arg … ]
Equivalent to
print -nz.
pwd [ -rLP ]
Print the absolute pathname of the current working directory. If the
-ror the-Pflag is specified, or theCHASE_LINKSoption is set and the-Lflag is not given, the printed path will not contain symbolic links.
r
Same as
fc -e -.
read [ -rszpqAclneE ] [ -t [ num ] ] [ -k [ num ] ] [ -d delim ]
[
-un ] [ [name][?prompt] ] [ name … ]Read one line and break it into fields using the characters in
$IFSas 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 thenREPLYis used for scalars andreplyfor arrays.
-rRaw 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.
-sDon’t echo back characters if reading from the terminal.
-qRead only one character from the terminal and set name to
yif this character wasyorYand tonotherwise. With this flag set the return status is zero only if the character wasyorY. 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-uor-pis 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
-qis present. Input is read from the terminal unless one of-uor-pis present. This option may also be used within zle widgets.Note that despite the mnemonic `key’ this option does read full characters, which may consist of multiple bytes if the option
MULTIBYTEis set.
-zRead 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 -zor withpush-linefrom the line editor (see zshzle). This flag is ignored when the-kor-qflags are present.
-e
-EThe input read is printed (echoed) to the standard output. If the
-eflag is used, no input is assigned to the parameters.
-AThe first name is taken as the name of an array and all words are assigned to it.
-c
-lThese flags are allowed only if called inside a function used for completion (specified with the
-Kflag tocompctl). If the-cflag is given, the words of the current command are read. If the-lflag is given, the whole line is assigned as a scalar. If both flags are present,-lis used and-cis ignored.
-nTogether 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.
-unInput is read from file descriptor n.
-pInput is read from the coprocess.
-ddelimInput is terminated by the first character of delim instead of by newline. For compatibility with other shells, if delim is an empty string, input is terminated at the first NUL.
-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
readreturns immediately if no input is available. If no input is available, return status 1 and do not set any variables. .. only:: manThis option is not available when reading from the editor buffer with
-z, when called from within completion with-cor-l, with-qwhich clears the input queue before reading, or within zle where other mechanisms should be used to test for input. .. only:: manNote 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 -twill not read anything until an entire line has been typed. However, when reading from the terminal with-kinput 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 2can still block on the second character. Use two instances ofread -t -kif this is not what is wanted.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
readis 1 when an end-of-file is encountered, or when-cor-lis present and the command is not called from acompctlfunction, or as described for-q. Otherwise the value is 0.The behavior of some combinations of the
-k,-p,-q,-uand-zflags is undefined. Presently-qcancels all the others,-pcancels-u,-kcancels-z, and otherwise-zcancels both-pand-u.The
-cor-lflags cancel any and all of-kpquz.
readonly
Same as
typeset -r. With thePOSIX_BUILTINSoption set, same astypeset -gr.
rehash
Same as
hash -r.
return [ n ]
Causes a shell function or
.script to return to the invoking script with the return status specified by an arithmetic expression n. Also causes a non-interactive shell to exit, allowing files containing shell code to be used both as scripts and as autoloadable shell functions. For example, the following prints42:() { integer foo=40; return "foo + 2" } echo $?If n is omitted, the return status is that of the last command executed.
If
returnwas executed from a trap in aTRAPNAL function, the effect is different for zero and non-zero return status. With zero status (or after an implicit return at the end of the trap), the shell will return to whatever it was previously processing; with a non-zero status, the shell will behave as interrupted except that the return status of the trap is retained. Note that the numeric value of the signal which caused the trap is passed as the first argument, so the statementreturn "128+$1"will return the same status as if the signal had not been trapped.
sched
See The zsh/sched Module.
set [ {+|-}:var:options | {+|-}o [ option_name ] ] … [ {+|-}A [ name ] ]
[ arg … ]
Set the options for the shell and/or set the positional parameters, or declare and set an array. If the
-soption is given, it causes the specified arguments to be sorted before assigning them to the positional parameters (or to the array name if-Ais used). With+ssort arguments in descending order. For the meaning of the other flags, see zshoptions. Flags may be specified by name using the-ooption. If no option name is supplied with-o, the current option states are printed: see the description ofsetoptbelow for more information on the format. With+othey are printed in a form that can be used as input to the shell.If the
-Aflag 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
+Ais used and name is an array, the given arguments will replace the initial elements of that array; if no name is specified, all arrays are printed without their values.The behaviour of arguments after
-Aname or+Aname depends on whether the optionKSH_ARRAYSis set. If it is not set, all arguments following name are treated as values for the array, regardless of their form. If the option is set, normal option processing continues at that point; only regular arguments are treated as values for the array. This means thatset -A array -x -- foosets
arrayto-x -- fooifKSH_ARRAYSis not set, but sets the array tofooand turns on the option-xif it is set.If the
-Aflag is not present, but there are arguments beyond the options, the positional parameters are set. If the option list (if any) is terminated by--, and there are no further arguments, the positional parameters will be unset.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.For historical reasons,
set -is treated asset +xvandset -args asset +xv --args when in any other emulation mode than zsh’s native mode.
setcap
See The zsh/cap Module.
setopt [ {+|-}:var:options | {+|-}o option_name ] [ -m ] [ name … ]
Set the options for the shell. All options specified either with flags or by name are set.
If no arguments are supplied, the names of all options currently set are 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 Description of Options). Options that are on by default for the emulation are shown with the prefixnoonly if they are off, while other options are shown without the prefixnoand only if they are on. In addition to options changed from the default state by the user, any options activated automatically by the shell (for example,SHIN_STDINorINTERACTIVE) will be shown in the list. The format is further modified by the optionKSH_OPTION_PRINT, however the rationale for choosing options with or without thenoprefix remains the same in this case.If the
-mflag is given the arguments are taken as patterns (which should be quoted to protect them from filename expansion), 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 behaviour is different from that of
set -o. This is because`` set`` is regarded as a special builtin by the POSIX standard, butsetoptis not.
shift [ -p ] [ n ] [ name … ]
The positional parameters
${n+1``}`` … are renamed to$1…, where n is an arithmetic expression that defaults to 1. If any names are given then the arrays with these names are shifted instead of the positional parameters.If the option
-pis given arguments are instead removed (popped) from the end rather than the start of the array.
source file [ arg … ]
Same as
., except that the current directory is always searched and is always searched first, before directories in$path.
stat
See The zsh/stat Module.
suspend [ -f ]
Suspend the execution of the shell (send it a
SIGTSTP) until it receives aSIGCONT. Unless the-foption is given, this will refuse to suspend a login shell.
test [ arg … ]
[ [ arg … ] ]
Like the system version of
test. Added for compatibility; use conditional expressions instead (see Conditional Expressions). The main differences between the conditional expression syntax and thetestand[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.
times
Print the accumulated user and system times for the shell and for processes run from the shell.
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
SIGin front (e.g. 1, HUP, and SIGHUP are all the same signal).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
trapcommand with no arguments prints a list of commands associated with each signal.If sig is
ZERRthen arg will be executed after each command with a nonzero exit status.ERRis an alias forZERRon systems that have noSIGERRsignal (this is the usual case).If sig is
DEBUGthen arg will be executed before each command if the optionDEBUG_BEFORE_CMDis set (as it is by default), else after each command. Here, a `command’ is what is described as a `sublist’ in the shell grammar, see Simple Commands & Pipelines. IfDEBUG_BEFORE_CMDis set various additional features are available. First, it is possible to skip the next command by setting the optionERR_EXIT; see the description of theERR_EXIToption in zshoptions. Also, the shell parameterZSH_DEBUG_CMDis 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
0orEXITand thetrapstatement 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 is0orEXITand thetrapstatement is not executed inside the body of a function, then the command arg is executed when the shell terminates; the trap runs before anyzshexithook functions.
ZERR,DEBUG, andEXITtraps are not executed inside other traps.ZERRandDEBUGtraps are kept within subshells, while other traps are reset.Note that traps defined with the
trapbuiltin are slightly different from those defined asTRAPNAL () { … }, 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' DEBUGwill print the line number of a command executed after it has run, while
TRAPDEBUG() { print $LINENO; }will always print the number zero.
Alternative signal names are allowed as described under
killabove. Defining a trap under either name causes any trap under an alternative name to be removed. However, it is recommended that for consistency users stick exclusively to one name or another.
true [ arg … ]
Do nothing and return an exit status of 0.
ttyctl [ -fu ]
The
-foption freezes the tty (i.e. terminal or terminal emulator), and-uunfreezes it. 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. Thus,sttyand similar programs have no effect when the tty is frozen. Freezing the tty does not cause the current state to be remembered: instead, it causes future changes to the state to be blocked.Without options it reports whether the terminal is frozen or not.
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
STTYfor a means of initialising the tty before running external commands and/or freezing the tty around a single command.
type [ -wfpamsS ] name …
Equivalent to
whence -v.
typeset [ {+|-}AHUaghlmrtux ] [ {+|-}EFLRZip [ n ] ]
[
+] [ name[=value] … ]
typeset {+|-}n [ -g ] [ {+|-}r ] [ 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.
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. 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 optionTYPESET_TO_UNSETis set. When that option is set, the parameter attributes are recorded but the parameter remains unset.If the shell option
TYPESET_SILENTis 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.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,readonlyortypesetis 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 theGLOB_ASSIGNoption are not supported, and scalar values after=are not split further into words, even if expanded (regardless of the setting of theKSH_TYPESEToption; this option is obsolete).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
svarand an array parameteravaras if the assignments had beensvar="one word" avar=(several words)On the other hand:
# Normal builtin interface builtin typeset svar=$(echo two words)The
builtinkeyword causes the above to use the standard builtin interface totypesetin which argument parsing is performed in the same way as for other commands. This example creates a scalarsvarcontaining the valuetwoand another scalar parameterwordswith no value. An array value in this case would either cause an error or be treated as an obscure set of glob qualifiers.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 $varThe above sets the scalar parameter
svarto the valueval. Parentheses around the value withinvarwould not cause array assignment as they will be treated as ordinary characters when$varis 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}=nameThe 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
typesetafter 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 typesetdisables the reserved word interface totypeset, exposing the builtin interface, whiledisable typesetdisables the builtin. Note that disabling the reserved word interface fortypesetmay cause problems with the output oftypeset -p, which assumes the reserved word interface is available in order to restore array and associative array values.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 -rparam orreadonlyparam after the parameter assignment statement.The flag
-ncreates a named reference to another parameter. The second parameter need not exist at the time the reference is created. Only the-H,-g, and-rflags may be used in conjunction with-n, having their usual meanings. The-uflag is special and may be applied to alter the scope of the reference. The name so created may not be an array element nor use a subscript, but the value assigned may be any valid parameter name syntax, even a subscripted array element (including an associative array element) or an array slice, which is evaluated when the named reference is expanded. It is an error for a named reference to refer to itself, even indirectly through a chain of references. When-uis applied to a named reference, the parameter identified by value is always found in the calling function scope rather than the current local scope. In this case, if there is no such parameter in the calling scope, assignments to the named reference may fail, setting$?to 1. See Parameter Expansion and Named References for details of the behavior of named references.Local function scoping rules for
typesetdo apply with-n, so a declaration within a function persists only until the end of the function unless-g -nis specified, and any local parameter (of any type) with the same name supplants a named reference from a surrounding scope.A scalar parameter, including an existing named reference, may be converted to a new named reference by
typeset -nname, so the-poption must be included to display the value of a specific named reference name.If no attribute flags are given, and either no name arguments are present or the flag
+mis used, then each parameter name printed is preceded by a list of the attributes of that parameter (array,association,exported,float,integer,readonly, orundefinedfor autoloaded parameters not yet loaded). If+mis used with attribute flags, and all those flags are introduced with+, the matching parameter names are printed but their values are not.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 totypeset +Uand displays the names of all arrays having the uniqueness attribute, whereastypeset -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 astypeset +m "*".
-gThe
-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+ghave any effect except in combination with-m(see below).
-mIf the
-mflag 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-fflag) with matching names are printed (the shell optionTYPESET_SILENTis not used in this case).If the
+gflag is combined with-m, a new local parameter is created for every matching parameter that is not already local. Otherwise-mapplies all other flags or assignments to the existing parameters, except that the-noption cannot create named references in this way.Except when assignments are made with name
=value, using+mforces the matching parameters and their attributes to be printed, even inside a function. Note that-mis ignored if no patterns are given, sotypeset -mdisplays attributes buttypeset -a +mdoes not. Ordinary scalar string parameters have no attributes, so for those+mprints only the names.
-p[ n ]If the
-poption 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-Hflag on parameters is respected; no value will be shown for these parameters.
-pmay be followed by an optional integer argument. Currently only the value1is supported. In this case arrays and associative arrays are printed with newlines between indented elements for readability.The names and values of readonly special parameters (most of the parameters marked `<S>’ in Parameters Set by the Shell, except those documented as settable) are not printed with
-pbecause to execute those typeset commands would cause errors. However, these parameters are printed when they have been made local to the scope wheretypeset -pis run.
-T[ scalar[=value] array[=(value …``)``] [ sep ] ]This flag has a different meaning when used with
-f; see below. Otherwise the-Toption requires zero, two, or three arguments to be present. With no arguments, the list of parameters created in this fashion is shown. With two or three arguments, the first two are the name of a scalar and of an array parameter (in that order) that will be tied together in the manner of$PATHand$path. The optional third argument is a single-character separator which will be used to join the elements of the array to form the scalar; if absent, 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.Only one of the scalar and array parameters may be assigned an initial value (the restrictions on assignment forms described above also apply).
Both the scalar and the array may be manipulated as normal. If one is unset, the other will automatically be unset too. There is no way of untying the variables without unsetting them, nor of converting the type of one of them with another
typesetcommand;+Tdoes 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 ...andexport -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-Tto 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.The following attribute flags may be specified:
-AThe names refer to associative array parameters; see Array Parameters.
-L[ n ]Left justify and remove 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.
The width is the count of characters, which may be multibyte characters if the
MULTIBYTEoption is in effect. Note that the screen width of the character is not taken into account; if this is required, use padding with parameter expansion flags${(ml…)…}as described in Parameter Expansion Flags.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
-Zflag is also set.
-R[ n ]Similar to
-L, except that right justification is used; when the parameter is expanded, the field is left filled with blanks or truncated from the end. May not be combined with the-Zflag.
-UFor 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 likePATHorFIGNORE, 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
-Lflag. 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.
-aThe names refer to array parameters. An array parameter may be created this way, but it may be assigned to in the
typesetstatement only if the reserved word form oftypesetis enabled (as it is by default). When displaying, both normal and associative arrays are shown.
-fThe names refer to functions rather than parameters. No assignments can be made, and the only other valid flags are
-t,-T,-k,-u,-Uand-z. The flag-tturns on execution tracing for this function; the flag-Tdoes the same, but turns off tracing for any named (not anonymous) function called from the present one, unless that function also has the-tor-Tflag. The-uand-Uflags cause the function to be marked for autoloading;-Ualso causes alias expansion to be suppressed when the function is loaded. See the description of theautoloadbuiltin for details.Note that the builtin
functionsprovides the same basic capabilities astypeset -fbut gives access to a few extra options;autoloadgives further additional options for the casetypeset -fuandtypeset -fU.
-hHide: only useful for special parameters (those marked `<S>’ in the table in Parameters Set by the Shell), 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 ofPATH. Alternatively, the local parameter may itself be given this attribute; hence inside a functiontypeset -h PATHcreates an ordinary local parameter and the specialPATHparameter is not altered in any way. It is also possible to create a local parameter usingtypeset +hspecial, where the local copy of special will retain its special properties regardless of having the-hattribute. Global special parameters loaded from shell modules (for example, those inzsh/mapfileandzsh/parameter) are automatically given the-hattribute to avoid name clashes.
-HHide value: specifies that
typesetwill not display the value of the parameter when listing parameters; the display for such parameters is always as if the+flag were given, but use of the parameter is in other respects normal. This effect does not apply when the parameter is specified by name or by pattern with the-moption. This is on by default for the parameters in thezsh/parameterandzsh/mapfilemodules. Note, however, that unlike the-hflag 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.
-lConvert the result to lower case whenever the parameter is expanded. The value is not converted when assigned.
-rThe 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_BUILTINSoption 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
-Uor-Zwould affect the value. More generally, the readonly attribute should not be relied on as a security mechanism.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.
-tTags the named parameters. Tags only exist to flag the parameter for the user’s own purposes — the list of tagged parameters can be queried using
typeset -t. Tags have no other use. Note that the-tflag has a different meaning when used with-f; see above.
-uConvert the result to upper case whenever the parameter is expanded. The value is not converted when assigned. This flag has different meanings when used with
-for-n; see above.
-xMark for automatic export to the environment of subsequently executed commands. If the option
GLOBAL_EXPORTis set, this implies the option-g, unless+gis 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 [ -HSa ] [ { -bcdfiklmnpqrsTtvwx | -N resource } [ limit ] … ]
Set or display resource limits of the shell and the processes started by the shell. The value of limit can be a number in the unit specified below or one of the values
unlimited, which removes the limit on the resource, orhard, which uses the current value of the hard limit on the resource.By default, only soft limits are manipulated. If the
-Hflag is given use hard limits instead of soft limits. If the-Sflag is given together with the-Hflag set 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 are printed. When more than one resource value is printed, the limit name and unit is printed before each value.
When looping over multiple resources, the shell will abort immediately if it detects a badly formed argument. However, if it fails to set a limit for some other reason it will continue trying to set the remaining limits.
Not all the following resources are supported on all systems. Running
ulimit -awill show which are supported.
-aList all of the current resource limits.
-bSocket buffer size in bytes (N.B. not kilobytes)
-c512-byte blocks on the size of core dumps.
-dKilobytes on the size of the data segment.
-eMaximum nice value.
-f512-byte blocks on the size of files written.
-iThe number of pending signals.
-kThe number of kqueues allocated.
-lKilobytes on the size of locked-in memory.
-mKilobytes on the size of physical memory.
-nOpen file descriptors.
-oMaximum number of POSIX thread library objects.
-pThe number of pseudo-terminals.
-qBytes in POSIX message queues.
-rMaximum real time priority. On some systems where this is not available, such as NetBSD, this has the same effect as
-Tfor compatibility withsh.-sKilobytes on the size of the stack.
-TThe number of simultaneous threads available to the user.
-tCPU seconds to be used.
-uThe number of processes available to the user.
-vKilobytes on the size of virtual memory. On some systems this refers to the limit called `address space’.
-wKilobytes on the size of swapped out memory.
-xThe number of locks on files.
-yMaximum size of buffers for pipes/fifos.
A resource may also be specified by integer in the form
-Nresource, where resource corresponds to the integer defined for the resource by the operating system. This may be used to set the limits for resources known to the shell which do not correspond to option letters. Such limits will be shown by number in the output ofulimit -a.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.
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
-Soption 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.
unalias [ -ams ] name …
Removes aliases. This command works the same as
unhash -a, except that the-aoption removes all regular or global aliases, or with-sall suffix aliases: in this case no name arguments may appear. The options-m(remove by pattern) and-swithout-a(remove listed suffix aliases) behave as forunhash -a. Note that the meaning of-ais different betweenunaliasandunhash.
unfunction
Same as
unhash -f.
unhash [ -adfms ] name …
Remove the element named name from an internal hash table. The default is remove elements from the command hash table. The
-aoption causesunhashto remove regular or global aliases; note when removing a global aliases that the argument must be quoted to prevent it from being expanded before being passed to the command. The-soption causesunhashto remove suffix aliases. The-foption causesunhashto remove shell functions. The-doptions causesunhashto remove named directories. If the-mflag is given the arguments are taken as patterns (should be quoted) and all elements of the corresponding hash table with matching names will be removed.
unlimit [ -hs ] resource …
The resource limit for each resource is set to the hard limit. If the
-hflag is given and the shell has appropriate privileges, the hard resource limit for each resource is removed. The resources of the shell process are only changed if the-sflag is given.The
unlimitcommand is not made available by default when the shell starts in a mode emulating another shell. It can be made available with the commandzmodload -F zsh/rlimits b:unlimit.
unset [ -fmv ] [ -n ] 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.
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.If the
-mflag is specified the arguments are taken as patterns (should be quoted) and all parameters with matching names are unset. Note that this cannot be used when unsetting associative array elements, as the subscript will be treated as part of the pattern.The
-vflag specifies that name refers to parameters. This is the default behaviour. If the-noption is supplied, and name is a a named reference, name will be unset rather than the variable it references.
unset -fis equivalent tounfunction. The-noption has no effect with-f.
unsetopt [ {+|-}:var:options | {+|-}o option_name ] [ name … ]
Unset 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
-mflag is given the arguments are taken as patterns (which should be quoted to preserve them from being interpreted as glob patterns), and all options with names matching these patterns are unset.
vared
See Zle Builtins.
wait [ job … ]
Wait 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_BUILTINSoption is set) and the exit status is 127.It is possible to wait for recent processes (specified by process ID, not by job) that were running in the background even if the process has exited. Typically the process ID will be recorded by capturing the value of the variable
$!immediately after the process has been started. There is a limit on the number of process IDs remembered by the shell; this is given by the value of the system configuration parameterCHILD_MAX. When this limit is reached, older process IDs are discarded, least recently started processes first.Note there is no protection against the process ID wrapping, i.e. if the wait is not executed soon enough there is a chance the process waited for is the wrong one. A conflict implies both process IDs have been generated by the shell, as other processes are not recorded, and that the user is potentially interested in both, so this problem is intrinsic to process IDs.
whence [ -vcwfpamsS ] [ -x num ] name …
For each name, indicate how it would be interpreted if used as a command name.
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-wwas passed – a message will be written to standard output. (This is different from other shells that write that message to standard error.)
whenceis most useful when name is only the last path component of a command, i.e. does not include a/; in particular, pattern matching only succeeds if just the non-directory component of the command is passed.
-vProduce a more verbose report.
-cPrint the results in a csh-like format. This takes precedence over
-v.
-wFor each name, print name
:word where word is one ofalias,builtin,command,function,hashed,reservedornone, according as name corresponds to an alias, a built-in command, an external command, a shell function, a command defined with thehashbuiltin, a reserved word, or is not recognised. This takes precedence over-vand-c.
-fCauses the contents of a shell function to be displayed, which would otherwise not happen unless the
-cflag were used.
-pDo a path search for name even if it is an alias, reserved word, shell function or builtin.
-aDo a search for all occurrences of name throughout the command path. Normally only the first occurrence is printed. When combined with
-m, only names appearing in the command hash table are searched, but all occurrences of those names are printed.
-mThe arguments are taken as patterns (pattern characters should be quoted), and the information is displayed for each entry in the command hash table matching one of these patterns. The hash table is first refilled, in case of changes to
PATH.
-sIf a pathname contains symlinks, print the symlink-free pathname as well.
-SAs
-s, but if the pathname had to be resolved by following multiple symlinks, the intermediate steps are printed, too. The symlink resolved at each step might be anywhere in the path.
-xnumExpand tabs when outputting shell functions using the
-coption. This has the same effect as the-xoption to thefunctionsbuiltin.
where [ -wpmsS ] [ -x num ] name …
Equivalent to
whence -ca.
which [ -wpamsS ] [ -x num ] name …
Equivalent to
whence -c.
zcompile [ -U ] [ -z | -k ] [ -R | -M ] file [ name … ]
zcompile -ca [ -m ] [ -R | -M ] file [ name … ]
zcompile -t file [ name … ]
This builtin command can be used to compile functions or scripts, storing the compiled form in a file, and to examine files containing the compiled form. This allows faster autoloading of functions and sourcing of scripts by avoiding parsing of the text when the files are read.
The first form (without the
-c,-aor-toptions) creates a compiled file. If only the file argument is given, the output file has the name file.zwcand will be placed in the same directory as the file. The shell will load the compiled file instead of the normal function file when the function is autoloaded; see Autoloading Functions for a description of how autoloaded functions are searched. The extension.zwcstands for `zsh word code’.If there is at least one name argument, all the named files are compiled into the output file given as the first argument. If file does not end in
.zwc, this extension is automatically appended. Files containing multiple compiled functions are called `digest’ files, and are intended to be used as elements of theFPATH/fpathspecial array.The second form, with the
-cor-aoptions, writes the compiled definitions for all the named functions into file. For-c, the names must be functions currently defined in the shell, not those marked for autoloading. Undefined functions that are marked for autoloading may be written by using the-aoption, in which case thefpathis searched and the contents of the definition files for those functions, if found, are compiled into file. If both-cand-aare given, names of both defined functions and functions marked for autoloading may be given. In either case, the functions in files written with the-cor-aoption will be autoloaded as if theKSH_AUTOLOADoption were unset.The reason for handling loaded and not-yet-loaded functions with different options is that some definition files for autoloading define multiple functions, including the function with the same name as the file, and, at the end, call that function. In such cases the output of
zcompile -cdoes not include the additional functions defined in the file, and any other initialization code in the file is lost. Usingzcompile -acaptures all this extra information.If the
-moption is combined with-cor-a, the names are used as patterns and all functions whose names match one of these patterns will be written. If no name is given, the definitions of all functions currently defined or marked as autoloaded will be written.Note the second form cannot be used for compiling functions that include redirections as part of the definition rather than within the body of the function; for example
fn1() { { ... } >~/logfile }can be compiled but
fn1() { ... } >~/logfilecannot. It is possible to use the first form of
zcompileto compile autoloadable functions that include the full function definition instead of just the body of the function.The third form, with the
-toption, examines an existing compiled file. Without further arguments, the names of the original files compiled into it are listed. The first line of output shows the version of the shell which 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 set to zero if definitions for all names were found in the compiled file, and non-zero if the definition for at least one name was not found.Other options:
-UAliases are not expanded when compiling the named files.
-RWhen the compiled file is read, its contents are copied into the shell’s memory, rather than memory-mapped (see
-M). This happens automatically on systems that do not support memory mapping.When compiling scripts instead of autoloadable functions, it is often desirable to use this option; otherwise the whole file, including the code to define functions which have already been defined, will remain mapped, consequently wasting memory.
-MThe compiled file is mapped into the shell’s memory when read. This is done in such a way that multiple instances of the shell running on the same host will share this mapped file. If neither
-Rnor-Mis given, thezcompilebuiltin decides what to do based on the size of the compiled file.
-k
-zThese options are used when the compiled file contains functions which are to be autoloaded. If
-zis given, the function will be autoloaded as if theKSH_AUTOLOADoption is not set, even if it is set at the time the compiled file is read, while if the-kis given, the function will be loaded as ifKSH_AUTOLOADis set. These options also take precedence over any-kor-zoptions specified to theautoloadbuiltin. If neither of these options is given, the function will be loaded as determined by the setting of theKSH_AUTOLOADoption at the time the compiled file is read. .. only:: manThese 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
-kor-z.The created file always contains two versions of the compiled format, one for big-endian machines and one for small-endian machines. The upshot of this is that the compiled file is machine independent and if it is read or mapped, only one half of the file is actually used (and mapped). .. only:: man
zformat
See The zsh/zutil Module.
zftp
See The zsh/zftp Module.
zle
See Zle Builtins.
zmodload [ -dL ] [ -s ] [ … ]
zmodload -F [ -alLme -P param ] module [ [+-]:var:feature … ]
zmodload -e [ -A ] [ … ]
zmodload [ -a [ -bcpf [ -I ] ] ] [ -iL ] …
zmodload -u [ -abcdpf [ -I ] ] [ -iL ] …
zmodload -A [ -L ] [ modalias[=module] … ]
zmodload -R modalias …
Performs operations relating to zsh’s loadable modules. Loading of modules while the shell is running (`dynamical loading’) is not available on all operating systems, or on all installations on a particular operating system, although the
zmodloadcommand itself is always available and can be used to manipulate modules built into versions of the shell executable without dynamical loading.Without arguments the names of all currently loaded binary modules are printed. The
-Loption causes this list to be in the form of a series ofzmodloadcommands. Forms with arguments are:
zmodload[-is] name …
zmodload-u[-i] name …In the simplest case,
zmodloadloads a binary module. The module must be in a file with a name consisting of the specified name followed by a standard suffix, usually.so(.slon HPUX). If the module to be loaded is already loaded the duplicate module is ignored. Ifzmodloaddetects an inconsistency, such as an invalid module name or circular dependency list, the current code block is aborted. If it is available, the module is loaded if necessary, while if it is not available, non-zero status is silently returned. The option-iis accepted for compatibility but has no effect.The named module is searched for in the same way a command is, using
$module_pathinstead of$path. However, the path search is performed even when the module name contains a/, which it usually does. There is no way to prevent the path search.If the module supports features (see below),
zmodloadtries to enable all features when loading a module. If the module was successfully loaded but not all features could be enabled,zmodloadreturns status 2.If the option
-sis given, no error is printed if the module was not available (though other errors indicating a problem with the module are printed). The return status indicates if the module was loaded. This is appropriate if the caller considers the module optional.With
-u,zmodloadunloads 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-ioption suppresses the error if the module is already unloaded (or was never loaded).Each module has a boot 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[-almLe-Pparam ] module [ [+-]:var:feature … ]
zmodload -Fallows 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 a+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.The standard features are builtins, conditions, parameters and math functions; these are indicated by the prefix
b:,c:(C:for an infix condition),p:andf:, respectively, followed by the name that the corresponding feature would have in the shell. For example,b:strftimeindicates a builtin namedstrftimeandp:EPOCHSECONDSindicates a parameter namedEPOCHSECONDS. The module may provide other (`abstract’) features of its own as indicated by its documentation; these have no prefix.With
-lor-L, features provided by the module are listed. With-lalone, a list of features together with their states is shown, one feature per line. With-Lalone, azmodload -Fcommand that would cause enabled features of the module to be turned on is shown. With-lL, azmodload -Fcommand 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-Pparam then the parameter param is set to an array of features, either features together with their state or (if-Lalone is given) enabled features.With the option
-Lthe module name may be omitted; then a list of all enabled features for all modules providing features is printed in the form ofzmodload -Fcommands. If-lis also given, the state of both enabled and disabled features is output in that form.A set of features may be provided together with
-lor-Land 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 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-aoption 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-land-Lmay 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 explicitzmodload -Famodule-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 -Fais run, an error message is printed and status 1 returned.
zmodload -Facan be used with the-l,-L,-eand-Poptions for listing and testing the existence of autoloadable features. In this case-lis ignored if-Lis specified.zmodload -FaLwith 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[-L] [ name ]
zmodload-dname dep …
zmodload-udname [ dep … ]The
-doption 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
-dand one argument, all dependencies for that module are listed. With-dand no arguments, all module dependencies are listed. This listing is by default in a Makefile-like format. The-Loption changes this format to a list ofzmodload -dcommands.If
-dand-uare both used, dependencies are removed. If only one argument is given, all dependencies for that module are removed.
zmodload-ab[-L]
zmodload-ab[-i] name [ builtin … ]
zmodload-ub[-i] builtin …The
-aboption 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 usezmodload -F -aas described above). If only the name is given, one builtin is defined, with the same name as the module.-isuppresses the error if the builtin is already defined or autoloaded, but not if another builtin of the same name is already defined.With
-aband no arguments, all autoloaded builtins are listed, with the module name (if different) shown in parentheses after the builtin name. The-Loption changes this format to a list ofzmodload -acommands.If
-bis used together with the-uoption, it removes builtins previously defined with-ab. This is only possible if the builtin is not yet loaded.-isuppresses 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 -ubbuiltin is issued.
zmodload-ac[-IL]
zmodload-ac[-iI] name [ cond … ]
zmodload-uc[-iI] cond …The
-acoption is used to define autoloaded condition codes. The cond strings give the names of the conditions defined by the module. The optional-Ioption 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
zmodloadcommands if the-Loption is given).The
-ucoption removes definitions for autoloaded conditions.
zmodload-ap[-L]
zmodload-ap[-i] name [ parameter … ]
zmodload-up[-i] parameter …The
-poption is like the-band-coptions, but makeszmodloadwork on autoloaded parameters instead.
zmodload-af[-L]
zmodload-af[-i] name [ function … ]
zmodload-uf[-i] function …The
-foption is like the-b,-p, and-coptions, but makeszmodloadwork on autoloaded math functions instead.
zmodload-a[-L]
zmodload-a[-i] name [ builtin … ]
zmodload-ua[-i] builtin …Equivalent to
-aband-ub.
zmodload -e[-A] [ string … ]The
-eoption without arguments lists all loaded modules; if the-Aoption is also given, module aliases corresponding to loaded modules are also shown. If arguments are provided, nothing is printed; the return status is set to zero if all strings given as arguments are names of loaded modules and to one if at least on string is not the name of a loaded module. This can be used to test for the availability of things implemented by modules. In this case, any aliases are automatically resolved and the-Aflag is not used.
zmodload-A[-L] [ modalias[=module] … ]For each argument, if both modalias and module are given, define modalias to be an alias for the module module. If the module modalias is ever subsequently requested, either via a call to
zmodloador implicitly, the shell will attempt to load module instead. If module is not given, show the definition of modalias. If no arguments are given, list all defined module aliases. When listing, if the-Lflag was also given, list the definition as azmodloadcommand to recreate the alias.The existence of aliases for modules is completely independent of whether the name resolved is actually loaded as a module: while the alias exists, loading and unloading the module under any alias has exactly the same effect as using the resolved name, and does not affect the connection between the alias and the resolved name which can be removed either by
zmodload -Ror by redefining the alias. Chains of aliases (i.e. where the first resolved name is itself an alias) are valid so long as these are not circular. As the aliases take the same format as module names, they may include path separators: in this case, there is no requirement for any part of the path named to exist as the alias will be resolved first. For example,any/old/aliasis always a valid alias.Dependencies added to aliased modules are actually added to the resolved module; these remain if the alias is removed. It is valid to create an alias whose name is one of the standard shell modules and which resolves to a different module. However, if a module has dependencies, it will not be possible to use the module name as an alias as the module will already be marked as a loadable module in its own right.
Apart from the above, aliases can be used in the
zmodloadcommand anywhere module names are required. However, aliases will not be shown in lists of loaded modules with a barezmodload.
zmodload-Rmodalias …For each modalias argument that was previously defined as a module alias via
zmodload -A, delete the alias. If any was not defined, an error is caused and the remainder of the line is ignored.Note that
zshmakes no distinction between modules that were linked into the shell and modules that are loaded dynamically. In both cases this builtin command has to be used to make available the builtins and other things defined by modules (unless the module is autoloaded on these definitions). This is true even for systems that don’t support dynamic loading of modules.
zparseopts
See The zsh/zutil Module.
zprof
See The zsh/zprof Module.
zpty
See The zsh/zpty Module.
zregexparse
See The zsh/zutil Module.
zsocket
See The zsh/net/socket Module.
zstyle
See The zsh/zutil Module.
ztcp
See The zsh/net/tcp Module.