Sophie

Sophie

distrib > Mageia > 7 > armv7hl > by-pkgid > 56cc9312e5d9c8cf446390cf4376339b > files > 241

zsh-doc-5.7.1-1.1.mga7.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created on February 3, 2019 by texi2html 5.0
texi2html was written by: 
            Lionel Cons <Lionel.Cons@cern.ch> (original author)
            Karl Berry  <karl@freefriends.org>
            Olaf Bachmann <obachman@mathematik.uni-kl.de>
            and many others.
Maintained by: Many creative people.
Send bugs and suggestions to <texi2html-bug@nongnu.org>
-->
<head>
<title>zsh: 22 Zsh Modules</title>

<meta name="description" content="zsh: 22 Zsh Modules">
<meta name="keywords" content="zsh: 22 Zsh Modules">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2html 5.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
pre.display {font-family: serif}
pre.format {font-family: serif}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: serif; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: serif; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:pre}
span.nolinebreak {white-space:pre}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>


</head>

<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">

<a name="Zsh-Modules"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Completion-Using-compctl" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Completion-Using-compctl.html#Example" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Description-4" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="Zsh-Modules-1"></a>
<h1 class="chapter">22 Zsh Modules</h1>
<a name="index-modules"></a>

<hr>
<a name="Description-4"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fattr-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h2 class="section">22.1 Description</h2>
<p>Some optional parts of zsh are in modules, separate from the core
of the shell.  Each of these modules may be linked in to the
shell at build time,
or can be dynamically linked while the shell is running
if the installation supports this feature.
Modules are linked at runtime with the <tt>zmodload</tt> command,
see <a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin Commands</a>.
</p>
<p>The modules that are bundled with the zsh distribution are:
</p>
<dl compact="compact">
<dt><tt>zsh/attr</tt></dt>
<dd><p>Builtins for manipulating extended attributes (xattr).
</p>
</dd>
<dt><tt>zsh/cap</tt></dt>
<dd><p>Builtins for manipulating POSIX.1e (POSIX.6) capability (privilege) sets.
</p>
</dd>
<dt><tt>zsh/clone</tt></dt>
<dd><p>A builtin that can clone a running shell onto another terminal.
</p>
</dd>
<dt><tt>zsh/compctl</tt></dt>
<dd><p>The <tt>compctl</tt> builtin for controlling completion.
</p>
</dd>
<dt><tt>zsh/complete</tt></dt>
<dd><p>The basic completion code.
</p>
</dd>
<dt><tt>zsh/complist</tt></dt>
<dd><p>Completion listing extensions.
</p>
</dd>
<dt><tt>zsh/computil</tt></dt>
<dd><p>A module with utility builtins needed for the shell function based
completion system.
</p>
</dd>
<dt><tt>zsh/curses</tt></dt>
<dd><p>curses windowing commands
</p>
</dd>
<dt><tt>zsh/datetime</tt></dt>
<dd><p>Some date/time commands and parameters.
</p>
</dd>
<dt><tt>zsh/db/gdbm</tt></dt>
<dd><p>Builtins for managing associative array parameters tied to GDBM databases.
</p>
</dd>
<dt><tt>zsh/deltochar</tt></dt>
<dd><p>A ZLE function duplicating EMACS&rsquo; <tt>zap-to-char</tt>.
</p>
</dd>
<dt><tt>zsh/example</tt></dt>
<dd><p>An example of how to write a module.
</p>
</dd>
<dt><tt>zsh/files</tt></dt>
<dd><p>Some basic file manipulation commands as builtins.
</p>
</dd>
<dt><tt>zsh/langinfo</tt></dt>
<dd><p>Interface to locale information.
</p>
</dd>
<dt><tt>zsh/mapfile</tt></dt>
<dd><p>Access to external files via a special associative array.
</p>
</dd>
<dt><tt>zsh/mathfunc</tt></dt>
<dd><p>Standard scientific functions for use in mathematical evaluations.
</p>
</dd>
<dt><tt>zsh/nearcolor</tt></dt>
<dd><p>Map colours to the nearest colour in the available palette.
</p>
</dd>
<dt><tt>zsh/newuser</tt></dt>
<dd><p>Arrange for files for new users to be installed.
</p>
</dd>
<dt><tt>zsh/parameter</tt></dt>
<dd><p>Access to internal hash tables via special associative arrays.
</p>
</dd>
<dt><tt>zsh/pcre</tt></dt>
<dd><p>Interface to the PCRE library.
</p>
</dd>
<dt><tt>zsh/param/private</tt></dt>
<dd><p>Builtins for managing private-scoped parameters in function context.
</p>
</dd>
<dt><tt>zsh/regex</tt></dt>
<dd><p>Interface to the POSIX regex library.
</p>
</dd>
<dt><tt>zsh/sched</tt></dt>
<dd><p>A builtin that provides a timed execution facility within the shell.
</p>
</dd>
<dt><tt>zsh/net/socket</tt></dt>
<dd><p>Manipulation of Unix domain sockets
</p>
</dd>
<dt><tt>zsh/stat</tt></dt>
<dd><p>A builtin command interface to the <tt>stat</tt> system call.
</p>
</dd>
<dt><tt>zsh/system</tt></dt>
<dd><p>A builtin interface to various low-level system features.
</p>
</dd>
<dt><tt>zsh/net/tcp</tt></dt>
<dd><p>Manipulation of TCP sockets
</p>
</dd>
<dt><tt>zsh/termcap</tt></dt>
<dd><p>Interface to the termcap database.
</p>
</dd>
<dt><tt>zsh/terminfo</tt></dt>
<dd><p>Interface to the terminfo database.
</p>
</dd>
<dt><tt>zsh/zftp</tt></dt>
<dd><p>A builtin FTP client.
</p>
</dd>
<dt><tt>zsh/zle</tt></dt>
<dd><p>The Zsh Line Editor, including the <tt>bindkey</tt> and <tt>vared</tt> builtins.
</p>
</dd>
<dt><tt>zsh/zleparameter</tt></dt>
<dd><p>Access to internals of the Zsh Line Editor via parameters.
</p>
</dd>
<dt><tt>zsh/zprof</tt></dt>
<dd><p>A module allowing profiling for shell functions.
</p>
</dd>
<dt><tt>zsh/zpty</tt></dt>
<dd><p>A builtin for starting a command in a pseudo-terminal.
</p>
</dd>
<dt><tt>zsh/zselect</tt></dt>
<dd><p>Block and return when file descriptors are ready.
</p>
</dd>
<dt><tt>zsh/zutil</tt></dt>
<dd><p>Some utility builtins, e.g. the one for supporting configuration via 
styles.
</p>
</dd>
</dl>
<table class="menu" border="0" cellspacing="0">
<tr><td align="left" valign="top"><a href="#The-zsh_002fattr-Module">22.2 The zsh/attr Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcap-Module">22.3 The zsh/cap Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fclone-Module">22.4 The zsh/clone Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcompctl-Module">22.5 The zsh/compctl Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcomplete-Module">22.6 The zsh/complete Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcomplist-Module">22.7 The zsh/complist Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcomputil-Module">22.8 The zsh/computil Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fcurses-Module">22.9 The zsh/curses Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fdatetime-Module">22.10 The zsh/datetime Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fdb_002fgdbm-Module">22.11 The zsh/db/gdbm Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fdeltochar-Module">22.12 The zsh/deltochar Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fexample-Module">22.13 The zsh/example Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002ffiles-Module">22.14 The zsh/files Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002flanginfo-Module">22.15 The zsh/langinfo Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fmapfile-Module">22.16 The zsh/mapfile Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fmathfunc-Module">22.17 The zsh/mathfunc Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fnearcolor-Module">22.18 The zsh/nearcolor Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fnewuser-Module">22.19 The zsh/newuser Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fparameter-Module">22.20 The zsh/parameter Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fpcre-Module">22.21 The zsh/pcre Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fparam_002fprivate-Module">22.22 The zsh/param/private Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fregex-Module">22.23 The zsh/regex Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fsched-Module">22.24 The zsh/sched Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fnet_002fsocket-Module">22.25 The zsh/net/socket Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fstat-Module">22.26 The zsh/stat Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fsystem-Module">22.27 The zsh/system Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fnet_002ftcp-Module">22.28 The zsh/net/tcp Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002ftermcap-Module">22.29 The zsh/termcap Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fterminfo-Module">22.30 The zsh/terminfo Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzftp-Module">22.31 The zsh/zftp Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzle-Module">22.32 The zsh/zle Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzleparameter-Module">22.33 The zsh/zleparameter Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzprof-Module">22.34 The zsh/zprof Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzpty-Module">22.35 The zsh/zpty Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzselect-Module">22.36 The zsh/zselect Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
<tr><td align="left" valign="top"><a href="#The-zsh_002fzutil-Module">22.37 The zsh/zutil Module</a></td><td>&nbsp;&nbsp;</td><td align="left" valign="top">
</td></tr>
</table>
<hr>
<a name="The-zsh_002fattr-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Description-4" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcap-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fattr-Module-1"></a>
<h2 class="section">22.2 The zsh/attr Module</h2>

<p>The <tt>zsh/attr</tt> module is used for manipulating extended attributes.
The <tt>-h</tt> option causes all commands to operate on symbolic links instead
of their targets.
The builtins in this module are:
</p>
<dl compact="compact">
<dd><a name="index-zgetattr"></a>
<a name="index-extended-attributes_002c-xattr_002c-getting-from-files"></a>
</dd>
<dt><tt>zgetattr</tt> [ <tt>-h</tt> ] <var>filename</var> <var>attribute</var> [ <var>parameter</var> ]</dt>
<dd><p>Get the extended attribute <var>attribute</var> from the specified
<var>filename</var>. If the optional argument <var>parameter</var> is given, the
attribute is set on that parameter instead of being printed to stdout.
</p>
<a name="index-zsetattr"></a>
<a name="index-extended-attributes_002c-xattr_002c-setting-on-files"></a>
</dd>
<dt><tt>zsetattr</tt> [ <tt>-h</tt> ] <var>filename</var> <var>attribute</var> <var>value</var></dt>
<dd><p>Set the extended attribute <var>attribute</var> on the specified
<var>filename</var> to <var>value</var>.
</p>
<a name="index-zdelattr"></a>
<a name="index-extended-attributes_002c-xattr_002c-removing_002c-deleting"></a>
</dd>
<dt><tt>zdelattr</tt> [ <tt>-h</tt> ] <var>filename</var> <var>attribute</var></dt>
<dd><p>Remove the extended attribute <var>attribute</var> from the specified
<var>filename</var>.
</p>
<a name="index-zlistattr"></a>
<a name="index-extended-attributes_002c-xattr_002c-listing"></a>
</dd>
<dt><tt>zlistattr</tt> [ <tt>-h</tt> ] <var>filename</var> [ <var>parameter</var> ]</dt>
<dd><p>List the extended attributes currently set on the specified
<var>filename</var>. If the optional argument <var>parameter</var> is given, the
list of attributes is set on that parameter instead of being printed to stdout.
</p>
</dd>
</dl>

<p><tt>zgetattr</tt> and <tt>zlistattr</tt> allocate memory dynamically.  If the
attribute or list of attributes grows between the allocation and the call
to get them, they return 2.  On all other errors, 1 is returned.  This
allows the calling function to check for this case and retry.
</p><hr>
<a name="The-zsh_002fcap-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fattr-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fclone-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcap-Module-1"></a>
<h2 class="section">22.3 The zsh/cap Module</h2>

<p>The <tt>zsh/cap</tt> module is used for manipulating POSIX.1e (POSIX.6) capability
sets.  If the operating system does not support this interface, the
builtins defined by this module will do nothing.
The builtins in this module are:
</p>
<dl compact="compact">
<dd><a name="index-cap"></a>
<a name="index-capabilities_002c-setting"></a>
</dd>
<dt><tt>cap</tt> [ <var>capabilities</var> ]</dt>
<dd><p>Change the shell&rsquo;s process capability sets to the specified <var>capabilities</var>,
otherwise display the shell&rsquo;s current capabilities.
</p>
<a name="index-getcap"></a>
<a name="index-capabilities_002c-getting-from-files"></a>
</dd>
<dt><tt>getcap</tt> <var>filename</var> ...</dt>
<dd><p>This is a built-in implementation of the POSIX standard utility.  It displays
the capability sets on each specified <var>filename</var>.
</p>
<a name="index-setcap"></a>
<a name="index-capabilities_002c-setting-on-files"></a>
</dd>
<dt><tt>setcap</tt> <var>capabilities</var> <var>filename</var> ...</dt>
<dd><p>This is a built-in implementation of the POSIX standard utility.  It sets
the capability sets on each specified <var>filename</var> to the specified
<var>capabilities</var>.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fclone-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcap-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcompctl-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fclone-Module-1"></a>
<h2 class="section">22.4 The zsh/clone Module</h2>

<p>The <tt>zsh/clone</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-clone"></a>
<a name="index-shell_002c-cloning"></a>
<a name="index-cloning-the-shell"></a>
<a name="index-terminal"></a>
</dd>
<dt><tt>clone</tt> <var>tty</var></dt>
<dd><p>Creates a forked instance of the current shell, attached to the specified
<var>tty</var>.  In the new shell, the <tt>PID</tt>, <tt>PPID</tt> and <tt>TTY</tt> special
parameters are changed appropriately.  <tt>$!</tt> is set to zero in the new
shell, and to the new shell&rsquo;s PID in the original shell.
</p>
<p>The return status of the builtin is zero in both shells if successful,
and non-zero on error.
</p>
<p>The target of <tt>clone</tt> should be an unused terminal, such as an unused virtual
console or a virtual terminal created by
</p>
<div class="example">
<pre class="example">xterm -e sh -c 'trap : INT QUIT TSTP; tty;
        while :; do sleep 100000000; done'
</pre></div>

<p>Some words of explanation are warranted about this long xterm command
line: when doing clone on a pseudo-terminal, some other session
(&quot;session&quot; meant as a unix session group, or SID) is already owning
the terminal. Hence the cloned zsh cannot acquire the pseudo-terminal
as a controlling tty. That means two things:
</p>
<ul>
<li> 
the job control signals will go to the sh-started-by-xterm process
group (that&rsquo;s why we disable INT QUIT and TSTP with trap; otherwise
the while loop could get suspended or killed)
</li><li> 
the cloned shell will have job control disabled, and the job
control keys (control-C, control-\ and control-Z) will not work.
</li></ul>

<p>This does not apply when cloning to an <em>unused</em> vc.
</p>
<p>Cloning to a used (and unprepared) terminal will result in two
processes reading simultaneously from the same terminal, with
input bytes going randomly to either process.
</p>
<p><tt>clone</tt> is mostly useful as a shell built-in replacement for
openvt.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fcompctl-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fclone-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplete-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcompctl-Module-1"></a>
<h2 class="section">22.5 The zsh/compctl Module</h2>

<p>The <tt>zsh/compctl</tt> module makes available two builtin commands. <tt>compctl</tt>,
is the old, deprecated way to control completions for ZLE.  See
<a href="Completion-Using-compctl.html#Completion-Using-compctl">Completion Using compctl</a>.
The other builtin command, <tt>compcall</tt> can be used in user-defined
completion widgets, see
<a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>.
</p><hr>
<a name="The-zsh_002fcomplete-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcompctl-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplist-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcomplete-Module-1"></a>
<h2 class="section">22.6 The zsh/complete Module</h2>

<p>The <tt>zsh/complete</tt> module makes available several builtin commands which
can be used in user-defined completion widgets, see
<a href="Completion-Widgets.html#Completion-Widgets">Completion Widgets</a>.
</p><hr>
<a name="The-zsh_002fcomplist-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplete-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Colored-completion-listings" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcomplist-Module-1"></a>
<h2 class="section">22.7 The zsh/complist Module</h2>

<a name="index-completion_002c-listing-1"></a>
<a name="index-completion_002c-coloured-listings"></a>
<a name="index-completion_002c-scroll-listings"></a>
<p>The <tt>zsh/complist</tt> module offers three extensions to completion listings:
the ability to highlight matches in such a list, the ability to
scroll through long lists and a different style of menu completion.
</p>

<hr>
<a name="Colored-completion-listings"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplist-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplist-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Scrolling-in-completion-listings" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.7.1 Colored completion listings</h3>
<p>Whenever one of the parameters <tt>ZLS_COLORS</tt> or <tt>ZLS_COLOURS</tt> is set 
and the <tt>zsh/complist</tt> module is loaded or linked into the shell,
completion lists will be colored.  Note, however, that <tt>complist</tt> will
not automatically be loaded if it is not linked in:  on systems with
dynamic loading, &lsquo;<tt>zmodload zsh/complist</tt>&rsquo; is required.
</p>
<a name="index-ZLS_005fCOLORS"></a>
<a name="index-ZLS_005fCOLOURS"></a>
<p>The parameters <tt>ZLS_COLORS</tt> and <tt>ZLS_COLOURS</tt> describe how matches
are highlighted.  To turn on highlighting an empty value suffices, in
which case all the default values given below will be used.  The format of
the value of these parameters is the same as used by the GNU version of the
<tt>ls</tt> command: a colon-separated list of specifications of the form
&lsquo;<var>name</var><tt>=</tt><var>value</var>&rsquo;.  The <var>name</var> may be one of the following strings,
most of which specify file types for which the <var>value</var> will be used.
The strings and their default values are:
</p>
<dl compact="compact">
<dt><tt>no 0</tt></dt>
<dd><p>for normal text (i.e. when displaying something other than a matched file)
</p>
</dd>
<dt><tt>fi 0</tt></dt>
<dd><p>for regular files
</p>
</dd>
<dt><tt>di 32</tt></dt>
<dd><p>for directories
</p>
</dd>
<dt><tt>ln 36</tt></dt>
<dd><p>for symbolic links.  If this has the special value <tt>target</tt>,
symbolic links are dereferenced and the target file used to
determine the display format.
</p>
</dd>
<dt><tt>pi 31</tt></dt>
<dd><p>for named pipes (FIFOs)
</p>
</dd>
<dt><tt>so 33</tt></dt>
<dd><p>for sockets
</p>
</dd>
<dt><tt>bd 44;37</tt></dt>
<dd><p>for block devices
</p>
</dd>
<dt><tt>cd 44;37</tt></dt>
<dd><p>for character devices
</p>
</dd>
<dt><tt>or</tt> <var>none</var></dt>
<dd><p>for a symlink to nonexistent file (default is the value defined for <tt>ln</tt>)
</p>
</dd>
<dt><tt>mi</tt> <var>none</var></dt>
<dd><p>for a non-existent file (default is the value defined for <tt>fi</tt>); this code
is currently not used
</p>
</dd>
<dt><tt>su 37;41</tt></dt>
<dd><p>for files with setuid bit set
</p>
</dd>
<dt><tt>sg 30;43</tt></dt>
<dd><p>for files with setgid bit set
</p>
</dd>
<dt><tt>tw 30;42</tt></dt>
<dd><p>for world writable directories with sticky bit set
</p>
</dd>
<dt><tt>ow 34;43</tt></dt>
<dd><p>for world writable directories without sticky bit set
</p>
</dd>
<dt><tt>sa</tt> <var>none</var></dt>
<dd><p>for files with an associated suffix alias; this is only tested
after specific suffixes, as described below
</p>
</dd>
<dt><tt>st 37;44</tt></dt>
<dd><p>for directories with sticky bit set but not world writable
</p>
</dd>
<dt><tt>ex 35</tt></dt>
<dd><p>for executable files
</p>
</dd>
<dt><tt>lc \e[</tt></dt>
<dd><p>for the left code (see below)
</p>
</dd>
<dt><tt>rc m</tt></dt>
<dd><p>for the right code
</p>
</dd>
<dt><tt>tc 0</tt></dt>
<dd><p>for the character indicating the file type  printed after filenames if
the <tt>LIST_TYPES</tt> option is set
</p>
</dd>
<dt><tt>sp 0</tt></dt>
<dd><p>for the spaces printed after matches to align the next column
</p>
</dd>
<dt><tt>ec</tt> <var>none</var></dt>
<dd><p>for the end code
</p>
</dd>
</dl>

<p>Apart from these strings, the <var>name</var> may also be an asterisk
(&lsquo;<tt>*</tt>&rsquo;) followed by any string. The <var>value</var> given for such a
string will be used for all files whose name ends with the string.
The <var>name</var> may also be an equals sign (&lsquo;<tt>=</tt>&rsquo;) followed by a
pattern; the <tt>EXTENDED_GLOB</tt> option will be turned on for evaluation
of the pattern.  The <var>value</var> given for this pattern will be used for all
matches (not just filenames) whose display string are matched by
the pattern.  Definitions for the form with the leading equal sign take
precedence over the values defined for file types, which in turn take
precedence over the form with the leading asterisk (file extensions).
</p>
<p>The leading-equals form also allows different parts of the displayed
strings to be colored differently.  For this, the pattern has to use the
&lsquo;<tt>(#b)</tt>&rsquo; globbing flag and pairs of parentheses surrounding the
parts of the strings that are to be colored differently.  In this case 
the <var>value</var> may consist of more than one color code separated by
equal signs.  The first code will be used for all parts for which no
explicit code is specified and the following codes will be used for
the parts matched by the sub-patterns in parentheses.  For example,
the specification &lsquo;<tt>=(#b)(?)*(?)=0=3=7</tt>&rsquo; will be used for all
matches which are at least two characters long and will use
the code &lsquo;<tt>3</tt>&rsquo; for the first character, &lsquo;<tt>7</tt>&rsquo; for the last
character and &lsquo;<tt>0</tt>&rsquo; for the rest.
</p>
<p>All three forms of <var>name</var> may be preceded by a pattern in
parentheses.  If this is given, the <var>value</var> will be used
only for matches in groups whose names are matched by the pattern
given in the parentheses.  For example, &lsquo;<tt>(g*)m*=43</tt>&rsquo; highlights all
matches beginning with &lsquo;<tt>m</tt>&rsquo; in groups whose names  begin with
&lsquo;<tt>g</tt>&rsquo; using the color code &lsquo;<tt>43</tt>&rsquo;.  In case of the &lsquo;<tt>lc</tt>&rsquo;,
&lsquo;<tt>rc</tt>&rsquo;, and &lsquo;<tt>ec</tt>&rsquo; codes, the group pattern is ignored.
</p>
<p>Note also that all patterns are tried in the order in which they
appear in the parameter value until the first one matches which is
then used.  Patterns may be matched against completions, descriptions
(possibly with spaces appended for padding), or lines consisting of a
completion followed by a description.  For consistent coloring it may be
necessary to use more than one pattern or a pattern with backreferences.
</p>
<p>When printing a match, the code prints the value of <tt>lc</tt>, the value
for the file-type or the last matching specification with a &lsquo;<tt>*</tt>&rsquo;,
the value of <tt>rc</tt>, the string to display for the match itself, and
then the value of <tt>ec</tt> if that is defined or the values of <tt>lc</tt>,
<tt>no</tt>, and <tt>rc</tt> if <tt>ec</tt> is not defined.
</p>
<p>The default values are ISO 6429 (ANSI) compliant and can be used on
vt100 compatible terminals such as <tt>xterm</tt>s.  On monochrome terminals
the default values will have no visible effect.  The <tt>colors</tt>
function from the contribution can be used to get associative arrays
containing the codes for ANSI terminals (see
<a href="User-Contributions.html#Other-Functions">Other Functions</a>).  For example, after loading <tt>colors</tt>, one could use
&lsquo;<tt>$color[red]</tt>&rsquo; to get the code for foreground color red and
&lsquo;<tt>$color[bg-green]</tt>&rsquo; for the code for background color green.
</p>
<p>If the completion system invoked by compinit is used, these
parameters should not be set directly because the system controls them 
itself.  Instead, the <tt>list-colors</tt> style should be used (see
<a href="Completion-System.html#Completion-System-Configuration">Completion System Configuration</a>).
</p>

<hr>
<a name="Scrolling-in-completion-listings"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Colored-completion-listings" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplist-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Menu-selection" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.7.2 Scrolling in completion listings</h3>
<p>To enable scrolling through a completion list, the <tt>LISTPROMPT</tt>
parameter must be set.  Its value will be used as the prompt; if it
is the empty string, a default prompt will be used.  The value may
contain escapes of the form &lsquo;<tt>%x</tt>&rsquo;.  It supports the escapes
&lsquo;<tt>%B</tt>&rsquo;, &lsquo;<tt>%b</tt>&rsquo;, &lsquo;<tt>%S</tt>&rsquo;, &lsquo;<tt>%s</tt>&rsquo;, &lsquo;<tt>%U</tt>&rsquo;, &lsquo;<tt>%u</tt>&rsquo;, &lsquo;<tt>%F</tt>&rsquo;,
&lsquo;<tt>%f</tt>&rsquo;, &lsquo;<tt>%K</tt>&rsquo;, &lsquo;<tt>%k</tt>&rsquo; and
&lsquo;<tt>%{</tt><var>...</var><tt>%}</tt>&rsquo; used also in shell prompts as well as three pairs of
additional sequences: a &lsquo;<tt>%l</tt>&rsquo; or &lsquo;<tt>%L</tt>&rsquo; is replaced by the number
of the last line shown and the total number of lines in the form
&lsquo;<var>number</var><tt>/</tt><var>total</var>&rsquo;; a &lsquo;<tt>%m</tt>&rsquo; or &lsquo;<tt>%M</tt>&rsquo; is replaced with
the number of the last match shown and the total number of matches; and 
&lsquo;<tt>%p</tt>&rsquo; or &lsquo;<tt>%P</tt>&rsquo; is replaced with &lsquo;<tt>Top</tt>&rsquo;, &lsquo;<tt>Bottom</tt>&rsquo; or the
position of the first line shown in percent of the total number of
lines, respectively.  In each of these cases the form with the uppercase
letter will be replaced with a string of fixed width, padded to the
right with spaces, while the lowercase form will not be padded.
</p>
<p>If the parameter <tt>LISTPROMPT</tt> is set, the completion code will not ask if
the list should be shown.  Instead it immediately starts displaying the
list, stopping after the first screenful, showing the prompt at the bottom,
waiting for a keypress after temporarily switching to the <tt>listscroll</tt>
keymap.  Some of the zle functions have a special meaning while scrolling
lists:
</p>
<dl compact="compact">
<dt><tt>send-break</tt></dt>
<dd><p>stops listing discarding the key pressed
</p>
</dd>
<dt><tt>accept-line</tt>, <tt>down-history</tt>, <tt>down-line-or-history</tt></dt>
<dt><tt>down-line-or-search</tt>, <tt>vi-down-line-or-history</tt></dt>
<dd><p>scrolls forward one line
</p>
</dd>
<dt><tt>complete-word</tt>, <tt>menu-complete</tt>, <tt>expand-or-complete</tt></dt>
<dt><tt>expand-or-complete-prefix</tt>, <tt>menu-complete-or-expand</tt></dt>
<dd><p>scrolls forward one screenful
</p>
</dd>
<dt><tt>accept-search</tt></dt>
<dd><p>stop listing but take no other action
</p>
</dd>
</dl>

<p>Every other character stops listing and immediately processes the key
as usual.  Any key that is not bound in the <tt>listscroll</tt> keymap or
that is bound to <tt>undefined-key</tt> is looked up in the keymap
currently selected.
</p>
<p>As for the <tt>ZLS_COLORS</tt> and <tt>ZLS_COLOURS</tt> parameters,
<tt>LISTPROMPT</tt> should not be set directly when using the shell
function based completion system.  Instead, the <tt>list-prompt</tt> style
should be used.
</p>

<hr>
<a name="Menu-selection"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Scrolling-in-completion-listings" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomplist-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomputil-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.7.3 Menu selection</h3>
<a name="index-completion_002c-selecting-by-cursor"></a>
<a name="index-MENUSELECT"></a>
<a name="index-menu_002dselect"></a>
<p>The <tt>zsh/complist</tt> module also offers an alternative style of selecting
matches from a list, called menu selection, which can be used if the
shell is set up to return to the last prompt after showing a
completion list (see the <tt>ALWAYS_LAST_PROMPT</tt> option in
<a href="Options.html#Options">Options</a>).
</p>
<p>Menu selection can be invoked directly by
the widget <tt>menu-select</tt> defined by this module.  This is a standard
ZLE widget that can be bound to a key in the usual way as described
in <a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>.
</p>
<p>Alternatively,
the parameter <tt>MENUSELECT</tt> can be set to an integer, which gives the
minimum number of matches that must be present before menu selection is
automatically turned on.  This second method requires that menu completion
be started, either directly from a widget such as <tt>menu-complete</tt>, or due
to one of the options <tt>MENU_COMPLETE</tt> or <tt>AUTO_MENU</tt> being set.  If
<tt>MENUSELECT</tt> is set, but is 0, 1 or empty, menu selection will always be
started during an ambiguous menu completion.
</p>
<p>When using the completion system based on shell functions, the
<tt>MENUSELECT</tt> parameter should not be used (like the <tt>ZLS_COLORS</tt>
and <tt>ZLS_COLOURS</tt> parameters described above).  Instead, the <tt>menu</tt> 
style should be used with the <tt>select=</tt><var>...</var> keyword.
</p>
<p>After menu selection is started, the matches will be listed. If there
are more matches than fit on the screen, only the first screenful is
shown.  The
matches to insert into the command line can be selected from this
list.  In the list one match is highlighted using the value for <tt>ma</tt>
from the <tt>ZLS_COLORS</tt> or <tt>ZLS_COLOURS</tt> parameter.  The default
value for this is &lsquo;<tt>7</tt>&rsquo; which forces the selected match to be
highlighted using standout mode on a vt100-compatible terminal.  If
neither <tt>ZLS_COLORS</tt> nor <tt>ZLS_COLOURS</tt> is set, the same terminal
control sequence as for the &lsquo;<tt>%S</tt>&rsquo; escape in prompts is used.
</p>
<p>If there are more matches than fit on the screen and the parameter
<tt>MENUPROMPT</tt> is set, its value will be shown below the matches.  It
supports the same escape sequences as <tt>LISTPROMPT</tt>, but the number
of the match or line shown will be that of the one where the mark is
placed.  If its value is the empty string, a default prompt will be
used.
</p>
<p>The <tt>MENUSCROLL</tt> parameter can be used to specify how the list is
scrolled.  If the parameter is unset, this is done line by line, if it
is set to &lsquo;<tt>0</tt>&rsquo; (zero), the list will scroll half the number of
lines of the screen.  If the value is positive, it gives the number of
lines to scroll and if it is negative, the list will be scrolled
the number of lines of the screen minus the (absolute) value.
</p>
<p>As for the <tt>ZLS_COLORS</tt>, <tt>ZLS_COLOURS</tt> and <tt>LISTPROMPT</tt>
parameters, neither <tt>MENUPROMPT</tt> nor <tt>MENUSCROLL</tt> should be
set directly when using the shell function based completion
system.  Instead, the <tt>select-prompt</tt> and <tt>select-scroll</tt> styles
should be used.
</p>
<p>The completion code sometimes decides not to show all of the matches
in the list.  These hidden matches are either matches for which the
completion function which added them explicitly requested that they
not appear in the list (using the <tt>-n</tt> option of the <tt>compadd</tt>
builtin command) or they are matches which duplicate a string already
in the list (because they differ only in things like prefixes or
suffixes that are not displayed).  In the list used for menu selection,
however, even these matches are shown so that it is possible to select
them.  To highlight such matches the <tt>hi</tt> and <tt>du</tt> capabilities in
the <tt>ZLS_COLORS</tt> and <tt>ZLS_COLOURS</tt> parameters are supported for
hidden matches of the first and second kind, respectively.
</p>
<p>Selecting matches is done by moving the mark around using the zle movement
functions.  When not all matches can be shown on the screen at the same 
time, the list will scroll up and down when crossing the top or
bottom line.  The following zle functions have special meaning during
menu selection.  Note that the following always
perform the same task within the menu selection map and cannot be
replaced by user defined widgets, nor can the set of functions
be extended:
</p>
<dl compact="compact">
<dt><tt>accept-line</tt>, <tt>accept-search</tt></dt>
<dd><p>accept the current match and leave menu selection (but do
not cause the command line to be accepted)
</p>
</dd>
<dt><tt>send-break</tt></dt>
<dd><p>leaves menu selection and restores the previous contents of the
command line
</p>
</dd>
<dt><tt>redisplay</tt>, <tt>clear-screen</tt></dt>
<dd><p>execute their normal function without leaving menu selection
</p>
</dd>
<dt><tt>accept-and-hold</tt>, <tt>accept-and-menu-complete</tt></dt>
<dd><p>accept the currently inserted match and continue selection allowing to 
select the next match to insert into the line
</p>
</dd>
<dt><tt>accept-and-infer-next-history</tt></dt>
<dd><p>accepts the current match and then tries completion with
menu selection again;  in the case of files this allows one to select
a directory and immediately attempt to complete files in it;  if there 
are no matches, a message is shown and one can use <tt>undo</tt> to go back 
to completion on the previous level, every other key leaves menu
selection (including the other zle functions which are otherwise
special during menu selection)
</p>
</dd>
<dt><tt>undo</tt></dt>
<dd><p>removes matches inserted during the menu selection by one of the three 
functions before
</p>
</dd>
<dt><tt>down-history</tt>, <tt>down-line-or-history</tt></dt>
<dt><tt>vi-down-line-or-history</tt>,  <tt>down-line-or-search</tt></dt>
<dd><p>moves the mark one line down
</p>
</dd>
<dt><tt>up-history</tt>, <tt>up-line-or-history</tt></dt>
<dt><tt>vi-up-line-or-history</tt>, <tt>up-line-or-search</tt></dt>
<dd><p>moves the mark one line up
</p>
</dd>
<dt><tt>forward-char</tt>, <tt>vi-forward-char</tt></dt>
<dd><p>moves the mark one column right
</p>
</dd>
<dt><tt>backward-char</tt>, <tt>vi-backward-char</tt></dt>
<dd><p>moves the mark one column left
</p>
</dd>
<dt><tt>forward-word</tt>, <tt>vi-forward-word</tt></dt>
<dt><tt>vi-forward-word-end</tt>, <tt>emacs-forward-word</tt></dt>
<dd><p>moves the mark one screenful down
</p>
</dd>
<dt><tt>backward-word</tt>, <tt>vi-backward-word</tt>, <tt>emacs-backward-word</tt></dt>
<dd><p>moves the mark one screenful up
</p>
</dd>
<dt><tt>vi-forward-blank-word</tt>, <tt>vi-forward-blank-word-end</tt></dt>
<dd><p>moves the mark to the first line of the next group of matches
</p>
</dd>
<dt><tt>vi-backward-blank-word</tt></dt>
<dd><p>moves the mark to the last line of the previous group of matches
</p>
</dd>
<dt><tt>beginning-of-history</tt></dt>
<dd><p>moves the mark to the first line
</p>
</dd>
<dt><tt>end-of-history</tt></dt>
<dd><p>moves the mark to the last line
</p>
</dd>
<dt><tt>beginning-of-buffer-or-history</tt>, <tt>beginning-of-line</tt></dt>
<dt><tt>beginning-of-line-hist</tt>, <tt>vi-beginning-of-line</tt></dt>
<dd><p>moves the mark to the leftmost column
</p>
</dd>
<dt><tt>end-of-buffer-or-history</tt>, <tt>end-of-line</tt></dt>
<dt><tt>end-of-line-hist</tt>, <tt>vi-end-of-line</tt></dt>
<dd><p>moves the mark to the rightmost column
</p>
</dd>
<dt><tt>complete-word</tt>, <tt>menu-complete</tt>, <tt>expand-or-complete</tt></dt>
<dt><tt>expand-or-complete-prefix</tt>, <tt>menu-expand-or-complete</tt></dt>
<dd><p>moves the mark to the next match
</p>
</dd>
<dt><tt>reverse-menu-complete</tt></dt>
<dd><p>moves the mark to the previous match
</p>
</dd>
<dt><tt>vi-insert</tt></dt>
<dd><p>this toggles between normal and interactive mode; in interactive mode
the keys bound to <tt>self-insert</tt> and <tt>self-insert-unmeta</tt> insert
into the command line as in normal editing mode but without leaving
menu selection; after each character completion is tried again and the
list changes to contain only the new matches; the completion widgets
make the longest unambiguous string be inserted in the command line
and <tt>undo</tt> and <tt>backward-delete-char</tt> go back to the previous set
of matches
</p>
</dd>
<dt><tt>history-incremental-search-forward</tt></dt>
<dt><tt>history-incremental-search-backward</tt></dt>
<dd><p>this starts incremental searches in the list of completions displayed;
in this mode, <tt>accept-line</tt> only leaves incremental search, going
back to the normal menu selection mode
</p>
</dd>
</dl>

<p>All movement functions wrap around at the edges; any other zle function not
listed leaves menu selection and executes that function.  It is possible to
make widgets in the above list do the same by using the form of the widget
with a &lsquo;<tt>.</tt>&rsquo; in front.  For example, the widget &lsquo;<tt>.accept-line</tt>&rsquo; has
the effect of leaving menu selection and accepting the entire command line.
</p>
<p>During this selection the widget uses the keymap <tt>menuselect</tt>.  Any
key that is not defined in this keymap or that is bound to
<tt>undefined-key</tt> is looked up in the keymap currently selected.  This
is used to ensure that the most important keys used during selection
(namely the cursor keys, return, and TAB) have sensible defaults.  However,
keys in the <tt>menuselect</tt> keymap can be modified directly using the
<tt>bindkey</tt> builtin command (see
<a href="#The-zsh_002fzle-Module">The zsh/zle Module</a>). For example, to make the return key leave menu selection without
accepting the match currently selected one could call
</p>
<div class="example">
<pre class="example">bindkey -M menuselect '^M' send-break
</pre></div>

<p>after loading the <tt>zsh/complist</tt> module.
</p><hr>
<a name="The-zsh_002fcomputil-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Menu-selection" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcurses-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcomputil-Module-1"></a>
<h2 class="section">22.8 The zsh/computil Module</h2>

<a name="index-completion_002c-utility"></a>
<p>The <tt>zsh/computil</tt> module adds several builtin commands that are used by
some of the completion functions in the completion system based on shell
functions (see 
<a href="Completion-System.html#Completion-System">Completion System</a>
).  Except for <tt>compquote</tt> these builtin commands are very
specialised and thus not very interesting when writing your own
completion functions.  In summary, these builtin commands are:
</p>
<dl compact="compact">
<dd><a name="index-comparguments"></a>
</dd>
<dt><tt>comparguments</tt></dt>
<dd><p>This is used by the <tt>_arguments</tt> function to do the argument and
command line parsing.  Like <tt>compdescribe</tt> it has an option <tt>-i</tt> to 
do the parsing and initialize some internal state and various options
to access the state information to decide what should be completed.
</p>
<a name="index-compdescribe"></a>
</dd>
<dt><tt>compdescribe</tt></dt>
<dd><p>This is used by the <tt>_describe</tt> function to build the displays for
the matches and to get the strings to add as matches with their
options.  On the first call one of the options <tt>-i</tt> or <tt>-I</tt> should be
supplied as the first argument.  In the first case, display strings without
the descriptions will be generated, in the second case, the string used to
separate the matches from their descriptions must be given as the
second argument and the descriptions (if any) will be shown.  All other 
arguments are like the definition arguments to <tt>_describe</tt> itself.
</p>
<p>Once <tt>compdescribe</tt> has been called with either the <tt>-i</tt> or the
<tt>-I</tt> option, it can be repeatedly called with the <tt>-g</tt> option and
the names of four parameters as its arguments.  This will step through
the different sets of matches and store the value of <tt>compstate[list]</tt>
in the first scalar, the options for <tt>compadd</tt> in the second array,
the matches in the third array, and the strings to be displayed in the
completion listing in the fourth array.  The arrays may then be directly
given to <tt>compadd</tt> to register the matches with the completion code.
</p>
<a name="index-compfiles"></a>
</dd>
<dt><tt>compfiles</tt></dt>
<dd><p>Used by the <tt>_path_files</tt> function to optimize complex recursive
filename generation (globbing).  It does three things.  With the
<tt>-p</tt> and <tt>-P</tt> options it builds the glob patterns to use,
including the paths already handled and trying to optimize the
patterns with respect to the prefix and suffix from the line and the
match specification currently used.  The <tt>-i</tt> option does the
directory tests for the <tt>ignore-parents</tt> style and the <tt>-r</tt> option 
tests if a component for some of the matches are equal to the string
on the line and removes all other matches if that is true.
</p>
<a name="index-compgroups"></a>
</dd>
<dt><tt>compgroups</tt></dt>
<dd><p>Used by the <tt>_tags</tt> function to implement the internals of the
<tt>group-order</tt> style.  This only takes its arguments as names of
completion groups and creates the groups for it (all six types: sorted 
and unsorted, both without removing duplicates, with removing all
duplicates and with removing consecutive duplicates).
</p>
<a name="index-compquote"></a>
</dd>
<dt><tt>compquote</tt> [ <tt>-p</tt> ] <var>names</var> ...</dt>
<dd><p>There may be reasons to write completion functions that have to add
the matches using the <tt>-Q</tt> option to <tt>compadd</tt> and perform quoting
themselves.  Instead of interpreting the first character of the
<tt>all_quotes</tt> key of the <tt>compstate</tt> special association and using
the <tt>q</tt> flag for parameter expansions, one can use this builtin
command.  The arguments are the names of scalar or array parameters
and the values of these parameters are quoted as needed for the
innermost quoting level.  If the <tt>-p</tt> option is given, quoting is
done as if there is some prefix before the values of the parameters,
so that a leading equal sign will not be quoted.
</p>
<p>The return status is non-zero in case of an error and zero otherwise.
</p>
<a name="index-comptags"></a>
<a name="index-comptry"></a>
</dd>
<dt><tt>comptags</tt></dt>
<dt><tt>comptry</tt></dt>
<dd><p>These implement the internals of the tags mechanism.
</p>
<a name="index-compvalues"></a>
</dd>
<dt><tt>compvalues</tt></dt>
<dd><p>Like <tt>comparguments</tt>, but for the <tt>_values</tt> function.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fcurses-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcomputil-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Builtin" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fcurses-Module-1"></a>
<h2 class="section">22.9 The zsh/curses Module</h2>

<p>The <tt>zsh/curses</tt> module makes available one builtin command and
various parameters.
</p>

<hr>
<a name="Builtin"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcurses-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcurses-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-2" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.9.1 Builtin</h3>

<dl compact="compact">
<dd><a name="index-zcurses"></a>
<a name="index-windows_002c-curses"></a>
</dd>
<dt><tt>zcurses</tt> <tt>init</tt></dt>
<dt><tt>zcurses</tt> <tt>end</tt></dt>
<dt><tt>zcurses</tt> <tt>addwin</tt> <var>targetwin</var> <var>nlines</var> <var>ncols</var> <var>begin_y</var> <var>begin_x</var> [ <var>parentwin</var> ]</dt>
<dt><tt>zcurses</tt> <tt>delwin</tt> <var>targetwin</var></dt>
<dt><tt>zcurses</tt> <tt>refresh</tt> [ <var>targetwin</var> ... ]</dt>
<dt><tt>zcurses</tt> <tt>touch</tt> <var>targetwin</var> ...</dt>
<dt><tt>zcurses</tt> <tt>move</tt> <var>targetwin</var> <var>new_y</var> <var>new_x</var></dt>
<dt><tt>zcurses</tt> <tt>clear</tt> <var>targetwin</var> [ <tt>redraw</tt> | <tt>eol</tt> | <tt>bot</tt> ]</dt>
<dt><tt>zcurses</tt> <tt>position</tt> <var>targetwin</var> <var>array</var></dt>
<dt><tt>zcurses</tt> <tt>char</tt> <var>targetwin</var> <var>character</var></dt>
<dt><tt>zcurses</tt> <tt>string</tt> <var>targetwin</var> <var>string</var></dt>
<dt><tt>zcurses</tt> <tt>border</tt> <var>targetwin</var> <var>border</var></dt>
<dt><tt>zcurses</tt> <tt>attr</tt> <var>targetwin</var> [ [<tt>+</tt>|<tt>-</tt>]<var>attribute</var> | <var>fg_col</var><tt>/</tt><var>bg_col</var> ] [...]</dt>
<dt><tt>zcurses</tt> <tt>bg</tt> <var>targetwin</var> [ [<tt>+</tt>|<tt>-</tt>]<var>attribute</var> | <var>fg_col</var><tt>/</tt><var>bg_col</var> | <tt>@</tt><var>char</var> ] [...]</dt>
<dt><tt>zcurses</tt> <tt>scroll</tt> <var>targetwin</var> [ <tt>on</tt> | <tt>off</tt> | [<tt>+</tt>|<tt>-</tt>]<var>lines</var> ]</dt>
<dt><tt>zcurses</tt> <tt>input</tt> <var>targetwin</var> [ <var>param</var> [ <var>kparam</var> [ <var>mparam</var> ] ] ]</dt>
<dt><tt>zcurses</tt> <tt>mouse</tt> [ <tt>delay</tt> <var>num</var> | [<tt>+</tt>|<tt>-</tt>]<tt>motion</tt> ]</dt>
<dt><tt>zcurses</tt> <tt>timeout</tt> <var>targetwin</var> <var>intval</var></dt>
<dt><tt>zcurses</tt> <tt>querychar</tt> <var>targetwin</var> [ <var>param</var> ]</dt>
<dt><tt>zcurses</tt> <tt>resize</tt> <var>height</var> <var>width</var> [ <tt>endwin</tt> | <tt>nosave</tt> | <tt>endwin_nosave</tt> ]</dt>
<dd><p>Manipulate curses windows.  All uses of this command should be
bracketed by &lsquo;<tt>zcurses init</tt>&rsquo; to initialise use of curses, and
&lsquo;<tt>zcurses end</tt>&rsquo; to end it; omitting &lsquo;<tt>zcurses end</tt>&rsquo; can cause
the terminal to be in an unwanted state.
</p>
<p>The subcommand <tt>addwin</tt> creates a window with <var>nlines</var> lines and
<var>ncols</var> columns.  Its upper left corner will be placed at row
<var>begin_y</var> and column
<var>begin_x</var> of the screen.  <var>targetwin</var> is a string and refers
to the name of a window that is not currently assigned.  Note
in particular the curses convention that vertical values appear
before horizontal values.
</p>
<p>If <tt>addwin</tt> is given an existing window as the final argument, the new
window is created as a subwindow of <var>parentwin</var>.  This differs from an
ordinary new window in that the memory of the window contents is shared
with the parent&rsquo;s memory.  Subwindows must be deleted before their parent.
Note that the coordinates of subwindows are relative to the screen, not
the parent, as with other windows.
</p>
<p>Use the subcommand <tt>delwin</tt> to delete a window created with
<tt>addwin</tt>.  Note that <tt>end</tt> does <em>not</em> implicitly delete windows,
and that <tt>delwin</tt> does not erase the screen image of the window.
</p>
<p>The window corresponding to the full visible screen is called
<tt>stdscr</tt>; it always exists after &lsquo;<tt>zcurses init</tt>&rsquo; and cannot
be delete with <tt>delwin</tt>.
</p>
<p>The subcommand <tt>refresh</tt> will refresh window <var>targetwin</var>; this is
necessary to make any pending changes (such as characters you have
prepared for output with <tt>char</tt>) visible on the screen.  <tt>refresh</tt>
without an argument causes the screen to be cleared and redrawn.
If multiple windows are given, the screen is updated once at the end.
</p>
<p>The subcommand <tt>touch</tt> marks the <var>targetwin</var>s listed as changed.
This is necessary before <tt>refresh</tt>ing windows if a window that
was in front of another window (which may be <tt>stdscr</tt>) is deleted.
</p>
<p>The subcommand <tt>move</tt> moves the cursor position in <var>targetwin</var> to
new coordinates <var>new_y</var> and <var>new_x</var>.  Note that the 
subcommand <tt>string</tt> (but not the subcommand <tt>char</tt>) advances the
cursor position over the characters added.
</p>
<p>The subcommand <tt>clear</tt> erases the contents of <var>targetwin</var>.  One
(and no more than one) of three options may be specified.  With the
option <tt>redraw</tt>, in addition the next <tt>refresh</tt> of <var>targetwin</var>
will cause the screen to be cleared and repainted.  With the option
<tt>eol</tt>, <var>targetwin</var> is only cleared to the end of the current cursor
line.  With the option
<tt>bot</tt>, <var>targetwin</var> is cleared to the end of the window, i.e
everything to the right and below the cursor is cleared.
</p>
<p>The subcommand <tt>position</tt> writes various positions associated with
<var>targetwin</var> into the array named <var>array</var>.
These are, in order:
</p><dl compact="compact">
<dt>-</dt>
<dd><p>The y and x coordinates of the cursor relative to the top left
of <var>targetwin</var>
</p></dd>
<dt>-</dt>
<dd><p>The y and x coordinates of the top left of <var>targetwin</var> on the
screen
</p></dd>
<dt>-</dt>
<dd><p>The size of <var>targetwin</var> in y and x dimensions.
</p></dd>
</dl>

<p>Outputting characters and strings are achieved by <tt>char</tt> and <tt>string</tt>
respectively.
</p>
<p>To draw a border around window <var>targetwin</var>, use <tt>border</tt>.  Note
that the border is not subsequently handled specially:  in other words,
the border is simply a set of characters output at the edge of the
window.  Hence it can be overwritten, can scroll off the window, etc.
</p>
<p>The subcommand <tt>attr</tt> will set <var>targetwin</var>&rsquo;s attributes or
foreground/background color pair for any successive character output.
Each <var>attribute</var> given on the line may be prepended by a <tt>+</tt> to set
or a <tt>-</tt> to unset that attribute; <tt>+</tt> is assumed if absent.  The
attributes supported are <tt>blink</tt>, <tt>bold</tt>, <tt>dim</tt>, <tt>reverse</tt>,
<tt>standout</tt>, and <tt>underline</tt>.
</p>
<p>Each <var>fg_col</var><tt>/</tt><var>bg_col</var> attribute (to be read as
&lsquo;<var>fg_col</var> on <var>bg_col</var>&rsquo;) sets the foreground and background color
for character output.  The color <tt>default</tt> is sometimes available
(in particular if the library is ncurses), specifying the foreground
or background color with which the terminal started.  The color pair
<tt>default/default</tt> is always available. To use more than the 8 named
colors (red, green, etc.) construct the <var>fg_col</var><tt>/</tt><var>bg_col</var>
pairs where <var>fg_col</var> and <var>bg_col</var> are decimal integers, e.g
<tt>128/200</tt>.  The maximum color value is 254 if the terminal supports
256 colors.
</p>
<p><tt>bg</tt> overrides the color and other attributes of all characters in the
window.  Its usual use is to set the background initially, but it will
overwrite the attributes of any characters at the time when it is called.
In addition to the arguments allowed with <tt>attr</tt>, an argument <tt>@</tt><var>char</var>
specifies a character to be shown in otherwise blank areas of the window.
Owing to limitations of curses this cannot be a multibyte character
(use of ASCII characters only is recommended).  As the specified set
of attributes override the existing background, turning attributes
off in the arguments is not useful, though this does not cause an error.
</p>
<p>The subcommand <tt>scroll</tt> can be used with <tt>on</tt> or <tt>off</tt> to enabled
or disable scrolling of a window when the cursor would otherwise move
below the window due to typing or output.  It can also be used with a
positive or negative integer to scroll the window up or down the given
number of lines without changing the current cursor position (which
therefore appears to move in the opposite direction relative to the
window).  In the second case, if scrolling is <tt>off</tt> it is temporarily
turned <tt>on</tt> to allow the window to be scrolled.
</p>
<p>The subcommand <tt>input</tt> reads a single character from the window
without echoing it back.  If <var>param</var> is supplied the character is
assigned to the parameter <var>param</var>, else it is assigned to the
parameter <tt>REPLY</tt>.
</p>
<p>If both <var>param</var> and <var>kparam</var> are supplied, the key is read in
&lsquo;keypad&rsquo; mode.  In this mode special keys such as function keys and
arrow keys return the name of the key in the parameter <var>kparam</var>.  The
key names are the macros defined in the <tt>curses.h</tt> or <tt>ncurses.h</tt>
with the prefix &lsquo;<tt>KEY_</tt>&rsquo; removed; see also the description of the
parameter <tt>zcurses_keycodes</tt> below.  Other keys cause a value to be
set in <var>param</var> as before.  On a successful return only one of
<var>param</var> or <var>kparam</var> contains a non-empty string; the other is set
to an empty string.
</p>
<p>If <var>mparam</var> is also supplied, <tt>input</tt> attempts to handle mouse
input.  This is only available with the ncurses library; mouse handling
can be detected by checking for the exit status of &lsquo;<tt>zcurses mouse</tt>&rsquo; with
no arguments.  If a mouse
button is clicked (or double- or triple-clicked, or pressed or released with
a configurable delay from being clicked) then <tt>kparam</tt> is set to the string
<tt>MOUSE</tt>, and <var>mparam</var> is set to an array consisting of the
following elements:
</p><dl compact="compact">
<dt>-</dt>
<dd><p>An identifier to discriminate different input devices; this
is only rarely useful.
</p></dd>
<dt>-</dt>
<dd><p>The x, y and z coordinates of the mouse click relative to
the full screen, as three elements in that order (i.e. the y coordinate
is, unusually, after the x coordinate).  The z coordinate is only
available for a few unusual input devices and is otherwise set to zero.
</p></dd>
<dt>-</dt>
<dd><p>Any events that occurred as separate items; usually
there will be just one.  An event consists of <tt>PRESSED</tt>, <tt>RELEASED</tt>,
<tt>CLICKED</tt>, <tt>DOUBLE_CLICKED</tt> or <tt>TRIPLE_CLICKED</tt> followed
immediately (in the same element) by the number of the button.
</p></dd>
<dt>-</dt>
<dd><p>If the shift key was pressed, the string <tt>SHIFT</tt>.
</p></dd>
<dt>-</dt>
<dd><p>If the control key was pressed, the string <tt>CTRL</tt>.
</p></dd>
<dt>-</dt>
<dd><p>If the alt key was pressed, the string <tt>ALT</tt>.
</p></dd>
</dl>

<p>Not all mouse events may be passed through to the terminal window;
most terminal emulators handle some mouse events themselves.  Note
that the ncurses manual implies that using input both with and
without mouse handling may cause the mouse cursor to appear and
disappear.
</p>
<p>The subcommand <tt>mouse</tt> can be used to configure the use of the mouse.
There is no window argument; mouse options are global.
&lsquo;<tt>zcurses mouse</tt>&rsquo; with no arguments returns status 0 if mouse handling
is possible, else status 1.  Otherwise, the possible arguments (which
may be combined on the same command line) are as follows.
<tt>delay</tt> <var>num</var> sets the maximum delay in milliseconds between press and
release events to be considered as a click; the value 0 disables click
resolution, and the default is one sixth of a second.  <tt>motion</tt> proceeded
by an optional &lsquo;<tt>+</tt>&rsquo; (the default) or <tt>-</tt> turns on or off
reporting of mouse motion in addition to clicks, presses and releases,
which are always reported.  However, it appears reports for mouse
motion are not currently implemented.
</p>
<p>The subcommand <tt>timeout</tt> specifies a timeout value for input from
<var>targetwin</var>.  If <var>intval</var> is negative, &lsquo;<tt>zcurses input</tt>&rsquo; waits
indefinitely for a character to be typed; this is the default.  If
<var>intval</var> is zero, &lsquo;<tt>zcurses input</tt>&rsquo; returns immediately; if there
is typeahead it is returned, else no input is done and status 1 is
returned.  If <var>intval</var> is positive, &lsquo;<tt>zcurses input</tt>&rsquo; waits
<var>intval</var> milliseconds for input and if there is none at the end of
that period returns status 1.
</p>
<p>The subcommand <tt>querychar</tt> queries the character at the current cursor
position.  The return values are stored in the array named <var>param</var> if
supplied, else in the array <tt>reply</tt>.  The first value is the character
(which may be a multibyte character if the system supports them); the
second is the color pair in the usual <var>fg_col</var><tt>/</tt><var>bg_col</var>
notation, or <tt>0</tt> if color is not supported.  Any attributes other than
color that apply to the character, as set with the subcommand <tt>attr</tt>,
appear as additional elements.
</p>
<p>The subcommand <tt>resize</tt> resizes <tt>stdscr</tt> and all windows to given
dimensions (windows that stick out from the new dimensions are resized
down). The underlying curses extension (<tt>resize_term call</tt>) can be
unavailable. To verify, zeroes can be used for <var>height</var> and
<var>width</var>. If the result of the subcommand is <tt>0</tt>, resize_term is
available (<tt>2</tt> otherwise). Tests show that resizing can be normally
accomplished by calling <tt>zcurses end</tt> and <tt>zcurses refresh</tt>. The
<tt>resize</tt> subcommand is provided for versatility. Multiple system
configurations have been checked and <tt>zcurses end</tt> and <tt>zcurses
refresh</tt> are still needed for correct terminal state after resize. To
invoke them with <tt>resize</tt>, use <var>endwin</var> argument.  Using
<var>nosave</var> argument will cause new terminal state to not be saved
internally by <tt>zcurses</tt>. This is also provided for versatility and
should normally be not needed.
</p>
</dd>
</dl>


<hr>
<a name="Parameters-2"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Builtin" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fcurses-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdatetime-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.9.2 Parameters</h3>

<dl compact="compact">
<dd><a name="index-ZCURSES_005fCOLORS"></a>
</dd>
<dt><tt>ZCURSES_COLORS</tt></dt>
<dd><p>Readonly integer.  The maximum number of colors the terminal
supports.  This value is initialised by the curses library and is not
available until the first time <tt>zcurses init</tt> is run.
</p>
<a name="index-ZCURSES_005fCOLOR_005fPAIRS"></a>
</dd>
<dt><tt>ZCURSES_COLOR_PAIRS</tt></dt>
<dd><p>Readonly integer.  The maximum number of color pairs
<var>fg_col</var><tt>/</tt><var>bg_col</var> that may be defined in &lsquo;<tt>zcurses attr</tt>&rsquo;
commands; note this limit applies to all color pairs that have been
used whether or not they are currently active.  This value is initialised
by the curses library and is not available until the first time <tt>zcurses
init</tt> is run.
</p>
<a name="index-zcurses_005fattrs"></a>
</dd>
<dt><tt>zcurses_attrs</tt></dt>
<dd><p>Readonly array.  The attributes supported by <tt>zsh/curses</tt>; available
as soon as the module is loaded.
</p>
<a name="index-zcurses_005fcolors"></a>
</dd>
<dt><tt>zcurses_colors</tt></dt>
<dd><p>Readonly array.  The colors supported by <tt>zsh/curses</tt>; available
as soon as the module is loaded.
</p>
<a name="index-zcurses_005fkeycodes"></a>
</dd>
<dt><tt>zcurses_keycodes</tt></dt>
<dd><p>Readonly array.  The values that may be returned in the second
parameter supplied to &lsquo;<tt>zcurses input</tt>&rsquo; in the order in which they
are defined internally by curses.  Not all function keys
are listed, only <tt>F0</tt>; curses reserves space for <tt>F0</tt> up to <tt>F63</tt>.
</p>
<a name="index-zcurses_005fwindows"></a>
</dd>
<dt><tt>zcurses_windows</tt></dt>
<dd><p>Readonly array.  The current list of windows, i.e. all windows that
have been created with &lsquo;<tt>zcurses addwin</tt>&rsquo; and not removed with
&lsquo;<tt>zcurses delwin</tt>&rsquo;.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fdatetime-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-2" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdb_002fgdbm-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fdatetime-Module-1"></a>
<h2 class="section">22.10 The zsh/datetime Module</h2>

<p>The <tt>zsh/datetime</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-strftime"></a>
<a name="index-date-string_002c-printing"></a>
</dd>
<dt><tt>strftime</tt> [ <tt>-s</tt> <var>scalar</var> ] <var>format</var> [ <var>epochtime</var> [ <var>nanoseconds</var> ] ]</dt>
<dt><tt>strftime</tt> <tt>-r</tt> [ <tt>-q</tt> ] [ <tt>-s</tt> <var>scalar</var> ] <var>format</var> <var>timestring</var></dt>
<dd><p>Output the date in the <var>format</var> specified.  With no <var>epochtime</var>, the
current system date/time is used; optionally, <var>epochtime</var> may be used to
specify the number of seconds since the epoch, and <var>nanoseconds</var> may
additionally be used to specify the number of nanoseconds past the second
(otherwise that number is assumed to be 0).
See man page strftime(3) for details.  The zsh extensions described in
<a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a> are also available.
</p>
<dl compact="compact">
<dt><tt>-q</tt></dt>
<dd><p>Run quietly; suppress printing of all error messages described below.
Errors for invalid <var>epochtime</var> values are always printed.
</p>
</dd>
<dt><tt>-r</tt></dt>
<dd><p>With the option <tt>-r</tt> (reverse), use <var>format</var> to parse the input
string <var>timestring</var> and output the number of seconds since the epoch at
which the time occurred.  The parsing is implemented by the system
function <tt>strptime</tt>; see man page strptime(3).  This means that zsh
format extensions are not available, but for reverse lookup they are not
required.
</p>
<p>In most implementations of <tt>strftime</tt> any timezone in the
<var>timestring</var> is ignored and the local timezone declared by the <tt>TZ</tt>
environment variable is used; other parameters are set to zero if not
present.
</p>
<p>If <var>timestring</var> does not match <var>format</var> the command returns status 1
and prints an error message.  If <var>timestring</var> matches <var>format</var> but
not all characters in <var>timestring</var> were used, the conversion succeeds
but also prints an error message.
</p>
<p>If either of the system functions <tt>strptime</tt> or <tt>mktime</tt> is not
available, status 2 is returned and an error message is printed.
</p>
</dd>
<dt><tt>-s</tt> <var>scalar</var></dt>
<dd><p>Assign the date string (or epoch time in seconds if <tt>-r</tt> is given) to
<var>scalar</var> instead of printing it.
</p>
</dd>
</dl>

<p>Note that depending on the system&rsquo;s declared integral time type,
<tt>strftime</tt> may produce incorrect results for epoch times greater than
2147483647 which corresponds to 2038-01-19 03:14:07 +0000.
</p>
</dd>
</dl>

<p>The <tt>zsh/datetime</tt> module makes available several parameters;
all are readonly:
</p>
<dl compact="compact">
<dd><a name="index-EPOCHREALTIME"></a>
</dd>
<dt><tt>EPOCHREALTIME</tt></dt>
<dd><p>A floating point value representing the number of seconds since
the epoch.  The notional accuracy is to nanoseconds if the
<tt>clock_gettime</tt> call is available and to microseconds otherwise,
but in practice the range of double precision floating point and
shell scheduling latencies may be significant effects.
</p>
<a name="index-EPOCHSECONDS"></a>
</dd>
<dt><tt>EPOCHSECONDS</tt></dt>
<dd><p>An integer value representing the number of seconds since the
epoch.
</p>
<a name="index-epochtime"></a>
</dd>
<dt><tt>epochtime</tt></dt>
<dd><p>An array value containing the number of seconds since the epoch
in the first element and the remainder of the time since the epoch
in nanoseconds in the second element.  To ensure the two elements
are consistent the array should be copied or otherwise referenced
as a single substitution before the values are used.  The following
idiom may be used:
</p>
<div class="example">
<pre class="example">for secs nsecs in $epochtime; do
  ...
done
</pre></div>


</dd>
</dl>
<hr>
<a name="The-zsh_002fdb_002fgdbm-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdatetime-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdeltochar-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fdb_002fgdbm-Module-1"></a>
<h2 class="section">22.11 The zsh/db/gdbm Module</h2>

<p>The <tt>zsh/db/gdbm</tt> module is used to create &quot;tied&quot; associative arrays
that interface to database files.  If the GDBM interface is not available,
the builtins defined by this module will report an error.  This module is
also intended as a prototype for creating additional database interfaces,
so the <tt>ztie</tt> builtin may move to a more generic module in the future.
</p>
<p>The builtins in this module are:
</p>
<dl compact="compact">
<dd><a name="index-ztie"></a>
<a name="index-database-tied-array_002c-creating"></a>
</dd>
<dt><tt>ztie -d db/gdbm -f</tt> <var>filename</var> [ <tt>-r</tt> ] <var>arrayname</var></dt>
<dd><p>Open the GDBM database identified by <var>filename</var> and, if successful,
create the associative array <var>arrayname</var> linked to the file.  To create
a local tied array, the parameter must first be declared, so commands
similar to the following would be executed inside a function scope:
</p>
<div class="example">
<pre class="example">local -A sampledb
ztie -d db/gdbm -f sample.gdbm sampledb
</pre></div>

<p>The <tt>-r</tt> option opens the database file for reading only, creating a
parameter with the readonly attribute.  Without this option, using
&lsquo;<tt>ztie</tt>&rsquo; on a file for which the user does not have write permission is
an error.  If writable, the database is opened synchronously so fields
changed in <var>arrayname</var> are immediately written to <var>filename</var>.
</p>
<p>Changes to the file modes <var>filename</var> after it has been opened do not
alter the state of <var>arrayname</var>, but &lsquo;<tt>typeset -r</tt> <var>arrayname</var>&rsquo;
works as expected.
</p>
<a name="index-zuntie"></a>
<a name="index-database-tied-array_002c-destroying"></a>
</dd>
<dt><tt>zuntie</tt> [ <tt>-u</tt> ] <var>arrayname</var> ...</dt>
<dd><p>Close the GDBM database associated with each <var>arrayname</var> and then
unset the parameter.  The <tt>-u</tt> option forces an unset of parameters
made readonly with &lsquo;<tt>ztie -r</tt>&rsquo;.
</p>
<p>This happens automatically if the parameter is explicitly unset or its
local scope (function) ends.  Note that a readonly parameter may not be
explicitly unset, so the only way to unset a global parameter created with
&lsquo;<tt>ztie -r</tt>&rsquo; is to use &lsquo;<tt>zuntie -u</tt>&rsquo;.
</p>
<a name="index-zgdbmpath"></a>
<a name="index-database-file-path_002c-reading"></a>
</dd>
<dt><tt>zgdbmpath</tt> <var>parametername</var></dt>
<dd><p>Put path to database file assigned to <var>parametername</var> into <tt>REPLY</tt>
scalar.
</p>
<a name="index-zgdbm_005ftied"></a>
<a name="index-database-tied-arrays_002c-enumerating"></a>
</dd>
<dt><tt>zgdbm_tied</tt></dt>
<dd><p>Array holding names of all tied parameters.
</p>
</dd>
</dl>

<p>The fields of an associative array tied to GDBM are neither cached nor
otherwise stored in memory, they are read from or written to the database
on each reference.  Thus, for example, the values in a readonly array may
be changed by a second writer of the same database file.
</p><hr>
<a name="The-zsh_002fdeltochar-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdb_002fgdbm-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fexample-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fdeltochar-Module-1"></a>
<h2 class="section">22.12 The zsh/deltochar Module</h2>

<p>The <tt>zsh/deltochar</tt> module makes available two ZLE functions:
</p>
<dl compact="compact">
<dd><a name="index-delete_002dto_002dchar"></a>
</dd>
<dt><tt>delete-to-char</tt></dt>
<dd><p>Read a character from the keyboard, and
delete from the cursor position up to and including the next
(or, with repeat count <var>n</var>, the <var>n</var>th) instance of that character.
Negative repeat counts mean delete backwards.
</p>
<a name="index-zap_002dto_002dchar"></a>
</dd>
<dt><tt>zap-to-char</tt></dt>
<dd><p>This behaves like <tt>delete-to-char</tt>, except that the final occurrence of
the character itself is not deleted.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fexample-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fdeltochar-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002ffiles-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fexample-Module-1"></a>
<h2 class="section">22.13 The zsh/example Module</h2>

<p>The <tt>zsh/example</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-example"></a>
<a name="index-modules_002c-example"></a>
<a name="index-modules_002c-writing"></a>
<a name="index-writing-modules"></a>
</dd>
<dt><tt>example</tt> [ <tt>-flags</tt> ] [ <var>args</var> ... ]</dt>
<dd><p>Displays the flags and arguments it is invoked with.
</p>
</dd>
</dl>

<p>The purpose of the module is to serve as an example of how to write a
module.
</p><hr>
<a name="The-zsh_002ffiles-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fexample-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002flanginfo-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002ffiles-Module-1"></a>
<h2 class="section">22.14 The zsh/files Module</h2>

<a name="index-files_002c-manipulating"></a>
<p>The <tt>zsh/files</tt> module makes available some common commands for file
manipulation as builtins; these commands are probably not needed for
many normal situations but can be useful in emergency recovery
situations with constrained resources.  The commands do not implement
all features now required by relevant standards committees.
</p>
<p>For all commands, a variant beginning <tt>zf_</tt> is also available and loaded
automatically.  Using the features capability of zmodload will let you load
only those names you want.  Note that it&rsquo;s possible to load only the
builtins with zsh-specific names using the following command:
</p>
<div class="example">
<pre class="example">zmodload -m -F zsh/files b:zf_\*
</pre></div>

<p>The commands loaded by default are:
</p>
<dl compact="compact">
<dd><a name="index-chgrp"></a>
</dd>
<dt><tt>chgrp</tt> [ <tt>-hRs</tt> ] <var>group</var> <var>filename</var> ...</dt>
<dd><p>Changes group of files specified.  This is equivalent to <tt>chown</tt> with
a <var>user-spec</var> argument of &lsquo;<tt>:</tt><var>group</var>&rsquo;.
</p>
<a name="index-chown"></a>
</dd>
<dt><tt>chown</tt> [ <tt>-hRs</tt> ] <var>user-spec</var> <var>filename</var> ...</dt>
<dd><p>Changes ownership and group of files specified.
</p>
<p>The <var>user-spec</var> can be in four forms:
</p>
<dl compact="compact">
<dt><var>user</var></dt>
<dd><p>change owner to <var>user</var>; do not change group
</p></dd>
<dt><var>user</var><tt>::</tt></dt>
<dd><p>change owner to <var>user</var>; do not change group
</p></dd>
<dt><var>user</var><tt>:</tt></dt>
<dd><p>change owner to <var>user</var>; change group to <var>user</var>&rsquo;s primary group
</p></dd>
<dt><var>user</var><tt>:</tt><var>group</var></dt>
<dd><p>change owner to <var>user</var>; change group to <var>group</var>
</p></dd>
<dt><tt>:</tt><var>group</var></dt>
<dd><p>do not change owner; change group to <var>group</var>
</p></dd>
</dl>

<p>In each case, the &lsquo;<tt>:</tt>&rsquo; may instead be a &lsquo;<tt>.</tt>&rsquo;.  The rule is that
if there is a &lsquo;<tt>:</tt>&rsquo; then the separator is &lsquo;<tt>:</tt>&rsquo;, otherwise
if there is a &lsquo;<tt>.</tt>&rsquo; then the separator is &lsquo;<tt>.</tt>&rsquo;, otherwise
there is no separator.
</p>
<p>Each of <var>user</var> and <var>group</var> may be either a username (or group name, as
appropriate) or a decimal user ID (group ID).  Interpretation as a name
takes precedence, if there is an all-numeric username (or group name).
</p>
<p>If the target is a symbolic link, the <tt>-h</tt> option causes <tt>chown</tt> to set
the ownership of the link instead of its target.
</p>
<p>The <tt>-R</tt> option causes <tt>chown</tt> to recursively descend into directories,
changing the ownership of all files in the directory after
changing the ownership of the directory itself.
</p>
<p>The <tt>-s</tt> option is a zsh extension to <tt>chown</tt> functionality.  It enables
paranoid behaviour, intended to avoid security problems involving
a <tt>chown</tt> being tricked into affecting files other than the ones
intended.  It will refuse to follow symbolic links, so that (for example)
&lsquo;&lsquo;<tt>chown luser /tmp/foo/passwd</tt>&rsquo;&rsquo; can&rsquo;t accidentally chown <tt>/etc/passwd</tt>
if <tt>/tmp/foo</tt> happens to be a link to <tt>/etc</tt>.  It will also check
where it is after leaving directories, so that a recursive chown of
a deep directory tree can&rsquo;t end up recursively chowning <tt>/usr</tt> as
a result of directories being moved up the tree.
</p>
<a name="index-ln"></a>
</dd>
<dt><tt>ln</tt> [ <tt>-dfhins</tt> ] <var>filename</var> <var>dest</var></dt>
<dt><tt>ln</tt> [ <tt>-dfhins</tt> ] <var>filename</var> ... <var>dir</var></dt>
<dd><p>Creates hard (or, with <tt>-s</tt>, symbolic) links.  In the first form, the
specified <var>dest</var>ination is created, as a link to the specified
<var>filename</var>.  In the second form, each of the <var>filename</var>s is
taken in turn, and linked to a pathname in the specified <var>dir</var>ectory
that has the same last pathname component.
</p>
<p>Normally, <tt>ln</tt> will not attempt to create hard links to
directories.  This check can be overridden using the <tt>-d</tt> option.
Typically only the super-user can actually succeed in creating
hard links to directories.
This does not apply to symbolic links in any case.
</p>
<p>By default, existing files cannot be replaced by links.
The <tt>-i</tt> option causes the user to be queried about replacing
existing files.  The <tt>-f</tt> option causes existing files to be
silently deleted, without querying.  <tt>-f</tt> takes precedence.
</p>
<p>The <tt>-h</tt> and <tt>-n</tt> options are identical and both exist for
compatibility; either one indicates that if the target is a symlink
then it should not be dereferenced.
Typically this is used in combination with <tt>-sf</tt> so that if an
existing link points to a directory then it will be removed,
instead of followed.
If this option is used with multiple filenames and the target
is a symbolic link pointing to a directory then the result is
an error.
</p>
<a name="index-mkdir"></a>
</dd>
<dt><tt>mkdir</tt> [ <tt>-p</tt> ] [ <tt>-m</tt> <var>mode</var> ] <var>dir</var> ...</dt>
<dd><p>Creates directories.  With the <tt>-p</tt> option, non-existing parent
directories are first created if necessary, and there will be
no complaint if the directory already exists.
The <tt>-m</tt> option can be used to specify (in octal) a set of file permissions
for the created directories, otherwise mode 777 modified by the current
<tt>umask</tt> (see man page umask(2)) is used.
</p>
<a name="index-mv"></a>
</dd>
<dt><tt>mv</tt> [ <tt>-fi</tt> ] <var>filename</var> <var>dest</var></dt>
<dt><tt>mv</tt> [ <tt>-fi</tt> ] <var>filename</var> ... <var>dir</var></dt>
<dd><p>Moves files.  In the first form, the specified <var>filename</var> is moved
to the specified <var>dest</var>ination.  In the second form, each of the
<var>filename</var>s is
taken in turn, and moved to a pathname in the specified <var>dir</var>ectory
that has the same last pathname component.
</p>
<p>By default, the user will be queried before replacing any file
that the user cannot write to, but writable files will be silently
removed.
The <tt>-i</tt> option causes the user to be queried about replacing
any existing files.  The <tt>-f</tt> option causes any existing files to be
silently deleted, without querying.  <tt>-f</tt> takes precedence.
</p>
<p>Note that this <tt>mv</tt> will not move files across devices.
Historical versions of <tt>mv</tt>, when actual renaming is impossible,
fall back on copying and removing files; if this behaviour is desired,
use <tt>cp</tt> and <tt>rm</tt> manually.  This may change in a future version.
</p>
<a name="index-rm"></a>
</dd>
<dt><tt>rm</tt> [ <tt>-dfirs</tt> ] <var>filename</var> ...</dt>
<dd><p>Removes files and directories specified.
</p>
<p>Normally, <tt>rm</tt> will not remove directories (except with the <tt>-r</tt>
option).  The <tt>-d</tt> option causes <tt>rm</tt> to try removing directories
with <tt>unlink</tt> (see man page unlink(2)), the same method used for files.
Typically only the super-user can actually succeed in unlinking
directories in this way.
<tt>-d</tt> takes precedence over <tt>-r</tt>.
</p>
<p>By default, the user will be queried before removing any file
that the user cannot write to, but writable files will be silently
removed.
The <tt>-i</tt> option causes the user to be queried about removing
any files.  The <tt>-f</tt> option causes files to be
silently deleted, without querying, and suppresses all error indications.
<tt>-f</tt> takes precedence.
</p>
<p>The <tt>-r</tt> option causes <tt>rm</tt> to recursively descend into directories,
deleting all files in the directory before removing the directory with
the <tt>rmdir</tt> system call (see man page rmdir(2)).
</p>
<p>The <tt>-s</tt> option is a zsh extension to <tt>rm</tt> functionality.  It enables
paranoid behaviour, intended to avoid common security problems involving
a root-run <tt>rm</tt> being tricked into removing files other than the ones
intended.  It will refuse to follow symbolic links, so that (for example)
&lsquo;&lsquo;<tt>rm /tmp/foo/passwd</tt>&rsquo;&rsquo; can&rsquo;t accidentally remove <tt>/etc/passwd</tt>
if <tt>/tmp/foo</tt> happens to be a link to <tt>/etc</tt>.  It will also check
where it is after leaving directories, so that a recursive removal of
a deep directory tree can&rsquo;t end up recursively removing <tt>/usr</tt> as
a result of directories being moved up the tree.
</p>
<a name="index-rmdir"></a>
</dd>
<dt><tt>rmdir</tt> <var>dir</var> ...</dt>
<dd><p>Removes empty directories specified.
</p>
<a name="index-sync"></a>
</dd>
<dt><tt>sync</tt></dt>
<dd><p>Calls the system call of the same name (see man page sync(2)), which
flushes dirty buffers to disk.  It might return before the I/O has
actually been completed.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002flanginfo-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002ffiles-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fmapfile-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002flanginfo-Module-1"></a>
<h2 class="section">22.15 The zsh/langinfo Module</h2>

<p>The <tt>zsh/langinfo</tt> module makes available one parameter:
</p>
<dl compact="compact">
<dd><a name="index-langinfo"></a>
</dd>
<dt><tt>langinfo</tt></dt>
<dd><p>An associative array that maps langinfo elements to
their values.
</p>
<p>Your implementation may support a number of the following keys:
</p>
<p><tt>CODESET</tt>,
<tt>D_T_FMT</tt>,
<tt>D_FMT</tt>,
<tt>T_FMT</tt>,
<tt>RADIXCHAR</tt>,
<tt>THOUSEP</tt>,
<tt>YESEXPR</tt>,
<tt>NOEXPR</tt>,
<tt>CRNCYSTR</tt>,
<tt>ABDAY_{1..7}</tt>,
<tt>DAY_{1..7}</tt>,
<tt>ABMON_{1..12}</tt>,
<tt>MON_{1..12}</tt>,
<tt>T_FMT_AMPM</tt>,
<tt>AM_STR</tt>,
<tt>PM_STR</tt>,
<tt>ERA</tt>,
<tt>ERA_D_FMT</tt>,
<tt>ERA_D_T_FMT</tt>,
<tt>ERA_T_FMT</tt>,
<tt>ALT_DIGITS</tt>
</p>

</dd>
</dl>
<hr>
<a name="The-zsh_002fmapfile-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002flanginfo-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Limitations" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fmapfile-Module-1"></a>
<h2 class="section">22.16 The zsh/mapfile Module</h2>

<a name="index-parameter_002c-file-access-via"></a>
<p>The <tt>zsh/mapfile</tt> module provides one special associative array parameter of
the same name.
</p>
<dl compact="compact">
<dd><a name="index-mapfile"></a>
</dd>
<dt><tt>mapfile</tt></dt>
<dd><p>This associative array takes as keys the names of files; the resulting
value is the content of the file.  The value is treated identically to any
other text coming from a parameter.  The value may also be assigned to, in
which case the file in question is written (whether or not it originally
existed); or an element may be unset, which will delete the file in
question.  For example, &lsquo;<tt>vared mapfile[myfile]</tt>&rsquo; works as expected,
editing the file &lsquo;<tt>myfile</tt>&rsquo;.
</p>
<p>When the array is accessed as a whole, the keys are the names of files in
the current directory, and the values are empty (to save a huge overhead in
memory).  Thus <tt>${(k)mapfile}</tt> has the same affect as the glob operator
<tt>*(D)</tt>, since files beginning with a dot are not special.  Care must be
taken with expressions such as <tt>rm ${(k)mapfile}</tt>, which will delete
every file in the current directory without the usual &lsquo;<tt>rm *</tt>&rsquo; test.
</p>
<p>The parameter <tt>mapfile</tt> may be made read-only; in that case, files
referenced may not be written or deleted.
</p>
<p>A file may conveniently be read into an array as one line per element
with the form
&lsquo;<var>array</var><tt>=(&quot;${(f@)mapfile[</tt><var>filename</var><tt>]}&quot;)</tt>&rsquo;.
The double quotes and the &lsquo;<tt>@</tt>&rsquo; are necessary to prevent empty lines
from being removed.  Note that if the file ends with a newline,
the shell will split on the final newline, generating an additional
empty field; this can be suppressed by using
&lsquo;<var>array</var><tt>=(&quot;${(f@)${mapfile[</tt><var>filename</var><tt>]%$&rsquo;\n&rsquo;}}&quot;)</tt>&rsquo;.
</p>
</dd>
</dl>


<hr>
<a name="Limitations"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fmapfile-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fmapfile-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fmathfunc-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.16.1 Limitations</h3>

<p>Although reading and writing of the file in question is efficiently
handled, zsh&rsquo;s internal memory management may be arbitrarily baroque;
however, <tt>mapfile</tt> is usually very much more efficient than
anything involving a loop.  Note in particular that
the whole contents of the file will always reside physically in memory when
accessed (possibly multiple times, due to standard parameter substitution
operations).  In particular, this means handling of sufficiently long files
(greater than the machine&rsquo;s swap space, or than the range of the pointer
type) will be incorrect.
</p>
<p>No errors are printed or flagged for non-existent, unreadable, or
unwritable files, as the parameter mechanism is too low in the shell
execution hierarchy to make this convenient.
</p>
<p>It is unfortunate that the mechanism for loading modules does not yet allow
the user to specify the name of the shell parameter to be given the special
behaviour.
</p><hr>
<a name="The-zsh_002fmathfunc-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Limitations" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnearcolor-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fmathfunc-Module-1"></a>
<h2 class="section">22.17 The zsh/mathfunc Module</h2>

<a name="index-functions_002c-mathematical"></a>
<a name="index-mathematical-functions"></a>
<p>The <tt>zsh/mathfunc</tt> module provides standard
mathematical functions for use when
evaluating mathematical formulae.  The syntax agrees with normal C and
FORTRAN conventions, for example,
</p>
<div class="example">
<pre class="example">(( f = sin(0.3) ))
</pre></div>

<p>assigns the sine of 0.3 to the parameter f.
</p>
<p>Most functions take floating point arguments and return a floating point
value.  However, any necessary conversions from or to integer type will be
performed automatically by the shell.  Apart from <tt>atan</tt> with a second
argument and the <tt>abs</tt>, <tt>int</tt> and <tt>float</tt> functions, all functions
behave as noted in the manual page for the corresponding C function,
except that any arguments out of range for the function in question will be
detected by the shell and an error reported.
</p>
<p>The following functions take a single floating point argument: <tt>acos</tt>,
<tt>acosh</tt>, <tt>asin</tt>, <tt>asinh</tt>, <tt>atan</tt>, <tt>atanh</tt>, <tt>cbrt</tt>, <tt>ceil</tt>,
<tt>cos</tt>, <tt>cosh</tt>, <tt>erf</tt>, <tt>erfc</tt>, <tt>exp</tt>, <tt>expm1</tt>, <tt>fabs</tt>,
<tt>floor</tt>, <tt>gamma</tt>, <tt>j0</tt>, <tt>j1</tt>, <tt>lgamma</tt>, <tt>log</tt>, <tt>log10</tt>,
<tt>log1p</tt>, <tt>log2</tt>, <tt>logb</tt>, <tt>sin</tt>, <tt>sinh</tt>, <tt>sqrt</tt>, <tt>tan</tt>,
<tt>tanh</tt>, <tt>y0</tt>, <tt>y1</tt>.  The <tt>atan</tt> function can optionally take a
second argument, in which case it behaves like the C function <tt>atan2</tt>.
The <tt>ilogb</tt> function takes a single floating point argument, but
returns an integer.
</p>
<p>The function <tt>signgam</tt> takes no arguments, and returns an integer, which
is the C variable of the same name, as described in man page gamma(3).  Note
that it is therefore only useful immediately after a call to <tt>gamma</tt> or
<tt>lgamma</tt>.  Note also that &lsquo;<tt>signgam()</tt>&rsquo; and &lsquo;<tt>signgam</tt>&rsquo; are
distinct expressions.
</p>
<p>The functions <tt>min</tt>, <tt>max</tt>, and <tt>sum</tt> are defined not in this module
but in the <tt>zmathfunc</tt> autoloadable function, described in
<a href="User-Contributions.html#Mathematical-Functions">Mathematical Functions</a>.
</p>
<p>The following functions take two floating point arguments: <tt>copysign</tt>,
<tt>fmod</tt>, <tt>hypot</tt>, <tt>nextafter</tt>.
</p>
<p>The following take an integer first argument and a floating point second
argument: <tt>jn</tt>, <tt>yn</tt>.
</p>
<p>The following take a floating point first argument and an integer second
argument: <tt>ldexp</tt>, <tt>scalb</tt>.
</p>
<p>The function <tt>abs</tt> does not convert the type of its single argument; it
returns the absolute value of either a floating point number or an
integer.  The functions <tt>float</tt> and <tt>int</tt> convert their arguments into
a floating point or integer value (by truncation) respectively.
</p>
<p>Note that the C <tt>pow</tt> function is available in ordinary math evaluation
as the &lsquo;<tt>**</tt>&rsquo; operator and is not provided here.
</p>
<p>The function <tt>rand48</tt> is available if your system&rsquo;s mathematical library
has the function <tt>erand48(3)</tt>.  It returns a pseudo-random floating point
number between 0 and 1.  It takes a single string optional argument.
</p>
<p>If the argument is not present, the random number seed is initialised by
three calls to the <tt>rand(3)</tt> function &mdash; this produces the
same random
numbers as the next three values of <tt>$RANDOM</tt>.
</p>
<p>If the argument is present, it gives the name of a scalar parameter where
the current random number seed will be stored.  On the first call, the
value must contain at least twelve hexadecimal digits (the remainder of the
string is ignored), or the seed will be initialised in the same manner as
for a call to <tt>rand48</tt> with no argument.  Subsequent calls to
<tt>rand48</tt>(<var>param</var>) will then maintain the seed in the
parameter <var>param</var> as a string of twelve hexadecimal digits, with no base
signifier.  The random number sequences for different parameters are
completely independent, and are also independent from that used by calls to
<tt>rand48</tt> with no argument.
</p>
<p>For example, consider
</p>
<div class="example">
<pre class="example">print $(( rand48(seed) ))
print $(( rand48() ))
print $(( rand48(seed) ))
</pre></div>

<p>Assuming <tt>$seed</tt> does not exist, it will be initialised by the first
call.  In the second call, the default seed is initialised; note, however,
that because of the properties of <tt>rand()</tt> there is a
correlation between
the seeds used for the two initialisations, so for more secure uses, you
should generate your own 12-byte seed.  The third call returns to the same
sequence of random numbers used in the first call, unaffected by the
intervening <tt>rand48()</tt>.
</p><hr>
<a name="The-zsh_002fnearcolor-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fmathfunc-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnewuser-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fnearcolor-Module-1"></a>
<h2 class="section">22.18 The zsh/nearcolor Module</h2>

<p>The <tt>zsh/nearcolor</tt> module replaces colours specified as hex triplets
with the nearest colour in the 88 or 256 colour palettes that are widely
used by terminal emulators.  By default, 24-bit true colour escape codes
are generated when colours are specified using hex triplets.  These are
not supported by all terminals.  The purpose of this module is to make
it easier to define colour preferences in a form that can work across a
range of terminal emulators.
</p>
<p>Aside from the default colour, the ANSI standard for terminal escape
codes provides for eight colours. The bright attribute brings this to
sixteen. These basic colours are commonly used in terminal applications
due to being widely supported. Expanded 88 and 256 colour palettes are
also common and, while the first sixteen colours vary somewhat between
terminals and configurations, these add a generally consistent and
predictable set of colours.
</p>
<p>In order to use the <tt>zsh/nearcolor</tt> module, it only needs to be
loaded. Thereafter, whenever a colour is specified using a hex triplet,
it will be compared against each of the available colours and the
closest will be selected. The first sixteen colours are never matched in
this process due to being unpredictable.
</p>
<p>It isn&rsquo;t possible to reliably detect support for true colour in the
terminal emulator. It is therefore recommended to be selective in
loading the <tt>zsh/nearcolor</tt> module. For example, the following
checks the <tt>COLORTERM</tt> environment variable:
</p>
<div class="example">
<pre class="example">[[ $COLORTERM = *(24bit|truecolor)* ]] || zmodload zsh/nearcolor
</pre></div>

<p>Note that some terminals accept the true color escape codes but map
them internally to a more limited palette in a similar manner to the
<tt>zsh/nearcolor</tt> module.
</p><hr>
<a name="The-zsh_002fnewuser-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnearcolor-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fparameter-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fnewuser-Module-1"></a>
<h2 class="section">22.19 The zsh/newuser Module</h2>

<p>The <tt>zsh/newuser</tt> module is loaded at boot if it is
available, the <tt>RCS</tt> option is set, and the <tt>PRIVILEGED</tt> option is not
set (all three are true by default).  This takes
place immediately after commands in the global <tt>zshenv</tt> file (typically
<tt>/etc/zshenv</tt>), if any, have been executed.  If the module is not
available it is silently ignored by the shell; the module may safely be
removed from <tt>$MODULE_PATH</tt> by the administrator if it is not required.
</p>
<p>On loading, the module tests if any of the start-up files <tt>.zshenv</tt>,
<tt>.zprofile</tt>, <tt>.zshrc</tt> or <tt>.zlogin</tt> exist in the directory given by
the environment variable <tt>ZDOTDIR</tt>, or the user&rsquo;s home directory if that
is not set.  The test is not performed and the module halts processing if
the shell was in an emulation mode (i.e. had been invoked as some other
shell than zsh).
</p>
<p>If none of the start-up files were found, the module then looks for the
file <tt>newuser</tt> first in a sitewide directory, usually the parent
directory of the <tt>site-functions</tt> directory, and if that is not found the
module searches in a version-specific directory, usually the parent of the
<tt>functions</tt> directory containing version-specific functions.  (These
directories can be configured when zsh is built using the
<tt>&ndash;enable-site-scriptdir=</tt><var>dir</var> and <tt>&ndash;enable-scriptdir=</tt><var>dir</var>
flags to <tt>configure</tt>, respectively; the defaults are
<var>prefix</var><tt>/share/zsh</tt> and <var>prefix</var><tt>/share/zsh/$ZSH_VERSION</tt> where
the default <var>prefix</var> is <tt>/usr/local</tt>.)
</p>
<p>If the file <tt>newuser</tt> is found, it is then sourced in the same manner as
a start-up file.  The file is expected to contain code to install start-up
files for the user, however any valid shell code will be executed.
</p>
<p>The <tt>zsh/newuser</tt> module is then unconditionally unloaded.
</p>
<p>Note that it is possible to achieve exactly the same effect as the
<tt>zsh/newuser</tt> module by adding code to <tt>/etc/zshenv</tt>.  The module
exists simply to allow the shell to make arrangements for new users without
the need for intervention by package maintainers and system administrators.
</p>
<p>The script supplied with the module invokes the shell function
<tt>zsh-newuser-install</tt>.  This may be invoked directly by the user
even if the <tt>zsh/newuser</tt> module is disabled.  Note, however, that
if the module is not installed the function will not be installed either.
The function is documented in
<a href="User-Contributions.html#User-Configuration-Functions">User Configuration Functions</a>.
</p><hr>
<a name="The-zsh_002fparameter-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnewuser-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fpcre-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fparameter-Module-1"></a>
<h2 class="section">22.20 The zsh/parameter Module</h2>

<a name="index-parameters_002c-special-1"></a>
<p>The <tt>zsh/parameter</tt> module gives access to some of the internal hash
tables used by the shell by defining some special parameters.
</p>
<dl compact="compact">
<dd><a name="index-options-1"></a>
</dd>
<dt><tt>options</tt></dt>
<dd><p>The keys for this associative array are the names of the options that
can be set and unset using the <tt>setopt</tt> and <tt>unsetopt</tt>
builtins. The value of each key is either the string <tt>on</tt> if the
option is currently set, or the string <tt>off</tt> if the option is unset.
Setting a key to one of these strings is like setting or unsetting
the option, respectively. Unsetting a key in this array is like
setting it to the value <tt>off</tt>.
</p>
<a name="index-commands"></a>
</dd>
<dt><tt>commands</tt></dt>
<dd><p>This array gives access to the command hash table. The keys are the
names of external commands, the values are the pathnames of the files
that would be executed when the command would be invoked. Setting a
key in this array defines a new entry in this table in the same way as
with the <tt>hash</tt> builtin. Unsetting a key as in &lsquo;<tt>unset
&quot;commands[foo]&quot;</tt>&rsquo; removes the entry for the given key from the command 
hash table.
</p>
<a name="index-functions-2"></a>
</dd>
<dt><tt>functions</tt></dt>
<dd><p>This associative array maps names of enabled functions to their
definitions. Setting a key in it is like defining a function with the
name given by the key and the body given by the value. Unsetting a key
removes the definition for the function named by the key.
</p>
<a name="index-dis_005ffunctions"></a>
</dd>
<dt><tt>dis_functions</tt></dt>
<dd><p>Like <tt>functions</tt> but for disabled functions.
</p>
<a name="index-functions_005fsource"></a>
</dd>
<dt><tt>functions_source</tt></dt>
<dd><p>This readonly associative array maps names of enabled functions to the
name of the file containing the source of the function.
</p>
<p>For an autoloaded function that has already been loaded, or marked for
autoload with an absolute path, or that has had its path resolved with
&lsquo;<tt>functions -r</tt>&rsquo;, this is the file found for autoloading, resolved
to an absolute path.
</p>
<p>For a function defined within the body of a script or sourced file,
this is the name of that file.  In this case, this is the exact path
originally used to that file, which may be a relative path.
</p>
<p>For any other function, including any defined at an interactive prompt or
an autoload function whose path has not yet been resolved, this is
the empty string.  However, the hash element is reported as defined
just so long as the function is present:  the keys to this hash are
the same as those to <tt>$funcions</tt>.
</p>
<a name="index-dis_005ffunctions_005fsource"></a>
</dd>
<dt><tt>dis_functions_source</tt></dt>
<dd><p>Like <tt>functions_source</tt> but for disabled functions.
</p>
<a name="index-builtins"></a>
</dd>
<dt><tt>builtins</tt></dt>
<dd><p>This associative array gives information about the builtin commands
currently enabled. The keys are the names of the builtin commands and
the values are either &lsquo;<tt>undefined</tt>&rsquo; for builtin commands that will
automatically be loaded from a module if invoked or &lsquo;<tt>defined</tt>&rsquo; for
builtin commands that are already loaded.
</p>
<a name="index-dis_005fbuiltins"></a>
</dd>
<dt><tt>dis_builtins</tt></dt>
<dd><p>Like <tt>builtins</tt> but for disabled builtin commands.
</p>
<a name="index-reswords"></a>
</dd>
<dt><tt>reswords</tt></dt>
<dd><p>This array contains the enabled reserved words.
</p>
<a name="index-dis_005freswords"></a>
</dd>
<dt><tt>dis_reswords</tt></dt>
<dd><p>Like <tt>reswords</tt> but for disabled reserved words.
</p>
<a name="index-patchars"></a>
</dd>
<dt><tt>patchars</tt></dt>
<dd><p>This array contains the enabled pattern characters.
</p>
<a name="index-dis_005fpatchars"></a>
</dd>
<dt><tt>dis_patchars</tt></dt>
<dd><p>Like <tt>patchars</tt> but for disabled pattern characters.
</p>
<a name="index-aliases"></a>
</dd>
<dt><tt>aliases</tt></dt>
<dd><p>This maps the names of the regular aliases currently enabled to their
expansions.
</p>
<a name="index-dis_005faliases"></a>
</dd>
<dt><tt>dis_aliases</tt></dt>
<dd><p>Like <tt>aliases</tt> but for disabled regular aliases.
</p>
<a name="index-galiases"></a>
</dd>
<dt><tt>galiases</tt></dt>
<dd><p>Like <tt>aliases</tt>, but for global aliases.
</p>
<a name="index-dis_005fgaliases"></a>
</dd>
<dt><tt>dis_galiases</tt></dt>
<dd><p>Like <tt>galiases</tt> but for disabled global aliases.
</p>
<a name="index-saliases"></a>
</dd>
<dt><tt>saliases</tt></dt>
<dd><p>Like <tt>raliases</tt>, but for suffix aliases.
</p>
<a name="index-dis_005fsaliases"></a>
</dd>
<dt><tt>dis_saliases</tt></dt>
<dd><p>Like <tt>saliases</tt> but for disabled suffix aliases.
</p>
<a name="index-parameters-1"></a>
</dd>
<dt><tt>parameters</tt></dt>
<dd><p>The keys in this associative array are the names of the parameters
currently defined. The values are strings describing the type of the
parameter, in the same format used by the <tt>t</tt> parameter flag, see
<a href="Expansion.html#Parameter-Expansion">Parameter Expansion</a>
.
Setting or unsetting keys in this array is not possible.
</p>
<a name="index-modules-1"></a>
</dd>
<dt><tt>modules</tt></dt>
<dd><p>An associative array giving information about modules. The keys are the names
of the modules loaded, registered to be autoloaded, or aliased. The
value says which state the named module is in and is one of the
strings &lsquo;<tt>loaded</tt>&rsquo;, &lsquo;<tt>autoloaded</tt>&rsquo;, or &lsquo;<tt>alias:</tt><var>name</var>&rsquo;,
where <var>name</var> is the name the module is aliased to.
</p>
<p>Setting or unsetting keys in this array is not possible.
</p>
<a name="index-dirstack"></a>
</dd>
<dt><tt>dirstack</tt></dt>
<dd><p>A normal array holding the elements of the directory stack. Note that
the output of the <tt>dirs</tt> builtin command includes one more
directory, the current working directory.
</p>
<a name="index-history-2"></a>
</dd>
<dt><tt>history</tt></dt>
<dd><p>This associative array maps history event numbers to the full history lines.
Although it is presented as an associative array, the array of all values
(<tt>${history[@]}</tt>) is guaranteed to be returned in order from most recent
to oldest history event, that is, by decreasing history event number.
</p>
<a name="index-historywords"></a>
</dd>
<dt><tt>historywords</tt></dt>
<dd><p>A special array containing the words stored in the history.  These also
appear in most to least recent order.
</p>
<a name="index-jobdirs"></a>
</dd>
<dt><tt>jobdirs</tt></dt>
<dd><p>This associative array maps job numbers to the directories from which the
job was started (which may not be the current directory of the job).
</p>
<p>The keys of the associative arrays are usually valid job numbers,
and these are the values output with, for example, <tt>${(k)jobdirs}</tt>.
Non-numeric job references may be used when looking up a value;
for example, <tt>${jobdirs[%+]}</tt> refers to the current job.
</p>
<a name="index-jobtexts"></a>
</dd>
<dt><tt>jobtexts</tt></dt>
<dd><p>This associative array maps job numbers to the texts of the command lines
that were used to start the jobs.
</p>
<p>Handling of the keys of the associative array is as described for
<tt>jobdirs</tt> above.
</p>
<a name="index-jobstates"></a>
</dd>
<dt><tt>jobstates</tt></dt>
<dd><p>This associative array gives information about the states of the jobs
currently known. The keys are the job numbers and the values are
strings of the form
&lsquo;<var>job-state</var><tt>:</tt><var>mark</var><tt>:</tt><var>pid</var><tt>=</tt><var>state</var>...&rsquo;. The
<var>job-state</var> gives the state the whole job is currently in, one of
&lsquo;<tt>running</tt>&rsquo;, &lsquo;<tt>suspended</tt>&rsquo;, or &lsquo;<tt>done</tt>&rsquo;. The <var>mark</var> is
&lsquo;<tt>+</tt>&rsquo; for the current job, &lsquo;<tt>-</tt>&rsquo; for the previous job and empty
otherwise. This is followed by one &lsquo;<tt>:</tt><var>pid</var><tt>=</tt><var>state</var>&rsquo; for every
process in the job. The <var>pid</var>s are, of course, the process IDs and
the <var>state</var> describes the state of that process.
</p>
<p>Handling of the keys of the associative array is as described for
<tt>jobdirs</tt> above.
</p>
<a name="index-nameddirs"></a>
</dd>
<dt><tt>nameddirs</tt></dt>
<dd><p>This associative array maps the names of named directories to the pathnames
they stand for.
</p>
<a name="index-userdirs"></a>
</dd>
<dt><tt>userdirs</tt></dt>
<dd><p>This associative array maps user names to the pathnames of their home
directories.
</p>
<a name="index-usergroups"></a>
</dd>
<dt><tt>usergroups</tt></dt>
<dd><p>This associative array maps names of system groups of which the current
user is a member to the corresponding group identifiers.  The contents
are the same as the groups output by the <tt>id</tt> command.
</p>
<a name="index-funcfiletrace"></a>
</dd>
<dt><tt>funcfiletrace</tt></dt>
<dd><p>This array contains the absolute line numbers and corresponding file
names for the point where the current function, sourced file, or (if
<tt>EVAL_LINENO</tt> is set) <tt>eval</tt> command was
called.  The array is of the same length as <tt>funcsourcetrace</tt> and
<tt>functrace</tt>, but differs from <tt>funcsourcetrace</tt> in that the line and
file are the point of call, not the point of definition, and differs
from <tt>functrace</tt> in that all values are absolute line numbers in
files, rather than relative to the start of a function, if any.
</p>
<a name="index-funcsourcetrace"></a>
</dd>
<dt><tt>funcsourcetrace</tt></dt>
<dd><p>This array contains the file names and line numbers of the
points where the functions, sourced files, and (if <tt>EVAL_LINENO</tt> is set)
<tt>eval</tt> commands currently being executed were
defined.  The line number is the line where the &lsquo;<tt>function</tt> <var>name</var>&rsquo;
or &lsquo;<var>name</var> <tt>()</tt>&rsquo; started.  In the case of an autoloaded
function  the line number is reported as zero.
The format of each element is <var>filename</var><tt>:</tt><var>lineno</var>.
</p>
<p>For functions autoloaded from a file in native zsh format, where only the
body of the function occurs in the file, or for files that have been
executed by the <tt>source</tt> or &lsquo;<tt>.</tt>&rsquo; builtins, the trace information is
shown as <var>filename</var><tt>:</tt><var>0</var>, since the entire file is the
definition.  The source file name is resolved to an absolute path when
the function is loaded or the path to it otherwise resolved.
</p>
<p>Most users will be interested in the information in the
<tt>funcfiletrace</tt> array instead.
</p>
<a name="index-funcstack"></a>
</dd>
<dt><tt>funcstack</tt></dt>
<dd><p>This array contains the names of the functions, sourced files,
and (if <tt>EVAL_LINENO</tt> is set) <tt>eval</tt> commands. currently being
executed. The first element is the name of the function using the
parameter.
</p>
<p>The standard shell array <tt>zsh_eval_context</tt> can be used to
determine the type of shell construct being executed at each depth:
note, however, that is in the opposite order, with the most recent
item last, and it is more detailed, for example including an
entry for <tt>toplevel</tt>, the main shell code being executed
either interactively or from a script, which is not present
in <tt>$funcstack</tt>.
</p>
<a name="index-functrace"></a>
</dd>
<dt><tt>functrace</tt></dt>
<dd><p>This array contains the names and line numbers of the callers
corresponding to the functions currently being executed.
The format of each element is <var>name</var><tt>:</tt><var>lineno</var>.
Callers are also shown for sourced files; the caller is the point
where the <tt>source</tt> or &lsquo;<tt>.</tt>&rsquo; command was executed.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fpcre-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fparameter-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fparam_002fprivate-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fpcre-Module-1"></a>
<h2 class="section">22.21 The zsh/pcre Module</h2>

<a name="index-regular-expressions_002c-perl_002dcompatible"></a>
<p>The <tt>zsh/pcre</tt> module makes some commands available as builtins:
</p>
<dl compact="compact">
<dd><a name="index-pcre_005fcompile"></a>
</dd>
<dt><tt>pcre_compile</tt> [ <tt>-aimxs</tt> ] <var>PCRE</var></dt>
<dd><p>Compiles a perl-compatible regular expression.
</p>
<p>Option <tt>-a</tt> will force the pattern to be anchored.
Option <tt>-i</tt> will compile a case-insensitive pattern.
Option <tt>-m</tt> will compile a multi-line pattern; that is,
<tt>^</tt> and <tt>$</tt> will match newlines within the pattern.
Option <tt>-x</tt> will compile an extended pattern, wherein
whitespace and <tt>#</tt> comments are ignored.
Option <tt>-s</tt> makes the dot metacharacter match all characters,
including those that indicate newline.
</p>
<a name="index-pcre_005fstudy"></a>
</dd>
<dt><tt>pcre_study</tt></dt>
<dd><p>Studies the previously-compiled PCRE which may result in faster
matching.
</p>
<a name="index-pcre_005fmatch"></a>
</dd>
<dt><tt>pcre_match</tt> [ <tt>-v</tt> <var>var</var> ] [ <tt>-a</tt> <var>arr</var> ] [ <tt>-n</tt> <var>offset</var> ] [ <tt>-b</tt> ] <var>string</var></dt>
<dd><p>Returns successfully if <tt>string</tt> matches the previously-compiled
PCRE.
</p>
<p>Upon successful match,
if the expression captures substrings within parentheses,
<tt>pcre_match</tt> will set the array <tt>match</tt> to those
substrings, unless the <tt>-a</tt> option is given, in which
case it will set the array <var>arr</var>.  Similarly, the variable
<tt>MATCH</tt> will be set to the entire matched portion of the
string, unless the <tt>-v</tt> option is given, in which case the variable
<var>var</var> will be set.
No variables are altered if there is no successful match.
A <tt>-n</tt> option starts searching for a match from the
byte <var>offset</var> position in <var>string</var>.  If the <tt>-b</tt> option is given,
the variable <tt>ZPCRE_OP</tt> will be set to an offset pair string,
representing the byte offset positions of the entire matched portion
within the <var>string</var>.  For example, a <tt>ZPCRE_OP</tt> set to &quot;32 45&quot; indicates
that the matched portion began on byte offset 32 and ended on byte offset 44.
Here, byte offset position 45 is the position directly after the matched
portion.  Keep in mind that the byte position isn&rsquo;t necessarily the same
as the character position when UTF-8 characters are involved.
Consequently, the byte offset positions are only to be relied on in the
context of using them for subsequent searches on <var>string</var>, using an offset
position as an argument to the <tt>-n</tt> option.  This is mostly
used to implement the &quot;find all non-overlapping matches&quot; functionality.
</p>
<p>A simple example of &quot;find all non-overlapping matches&quot;:
</p>
<div class="example">
<pre class="example">string=&quot;The following zip codes: 78884 90210 99513&quot;
pcre_compile -m &quot;\d{5}&quot;
accum=()
pcre_match -b -- $string
while [[ $? -eq 0 ]] do
    b=($=ZPCRE_OP)
    accum+=$MATCH
    pcre_match -b -n $b[2] -- $string
done
print -l $accum
</pre></div>

</dd>
</dl>

<p>The <tt>zsh/pcre</tt> module makes available the following test condition:
</p>
<dl compact="compact">
<dd><a name="index-pcre_002dmatch"></a>
</dd>
<dt><var>expr</var> <tt>-pcre-match</tt> <var>pcre</var></dt>
<dd><p>Matches a string against a perl-compatible regular expression.
</p>
<p>For example,
</p>
<div class="example">
<pre class="example">[[ &quot;$text&quot; -pcre-match ^d+$ ]] &amp;&amp;
print text variable contains only &quot;d's&quot;.
</pre></div>

<a name="index-REMATCH_005fPCRE-1"></a>
<a name="index-NO_005fCASE_005fMATCH-1"></a>
<p>If the <tt>REMATCH_PCRE</tt> option is set, the <tt>=~</tt> operator is equivalent to
<tt>-pcre-match</tt>, and the <tt>NO_CASE_MATCH</tt> option may be used.  Note that
<tt>NO_CASE_MATCH</tt> never applies to the <tt>pcre_match</tt> builtin, instead use
the <tt>-i</tt> switch of <tt>pcre_compile</tt>.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fparam_002fprivate-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fpcre-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fregex-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fparam_002fprivate-Module-1"></a>
<h2 class="section">22.22 The zsh/param/private Module</h2>

<p>The <tt>zsh/param/private</tt> module is used to create parameters whose scope
is limited to the current function body, and <em>not</em> to other functions
called by the current function.
</p>
<p>This module provides a single autoloaded builtin:
</p>
<dl compact="compact">
<dd><a name="index-private"></a>
<a name="index-private-parameter_002c-creating"></a>
</dd>
<dt><tt>private</tt> [ {<tt>+</tt>|<tt>-</tt>}<tt>AHUahlprtux</tt> ] [ {<tt>+</tt>|<tt>-</tt>}<tt>EFLRZi</tt> [ <var>n</var> ] ] [ <var>name</var>[<tt>=</tt><var>value</var>] ... ]</dt>
<dd><p>The <tt>private</tt> builtin accepts all the same options and arguments as <tt>local</tt>
(<a href="Shell-Builtin-Commands.html#Shell-Builtin-Commands">Shell Builtin Commands</a>) except
for the &lsquo;<tt>-</tt><tt>T</tt>&rsquo; option.  Tied parameters may not be made private.
</p>
<p>If used at the top level (outside a function scope), <tt>private</tt> creates a
normal parameter in the same manner as <tt>declare</tt> or <tt>typeset</tt>.  A
warning about this is printed if <tt>WARN_CREATE_GLOBAL</tt> is set
(<a href="Options.html#Options">Options</a>).  Used inside a
function scope, <tt>private</tt> creates a local parameter similar to one
declared with <tt>local</tt>, except having special properties noted below.
</p>
<p>Special parameters which expose or manipulate internal shell state, such
as <tt>ARGC</tt>, <tt>argv</tt>, <tt>COLUMNS</tt>, <tt>LINES</tt>, <tt>UID</tt>, <tt>EUID</tt>, <tt>IFS</tt>,
<tt>PROMPT</tt>, <tt>RANDOM</tt>, <tt>SECONDS</tt>, etc., cannot be made private unless
the &lsquo;<tt>-</tt><tt>h</tt>&rsquo; option is used to hide the special meaning of the
parameter.  This may change in the future.
</p>
</dd>
</dl>

<p>As with other <tt>typeset</tt> equivalents, <tt>private</tt> is both a builtin and a
reserved word, so arrays may be assigned with parenthesized word list
<var>name</var><tt>=(</tt><var>value</var>...<tt>)</tt> syntax.  However, the reserved
word &lsquo;<tt>private</tt>&rsquo; is not available until <tt>zsh/param/private</tt> is loaded,
so care must be taken with order of execution and parsing for function
definitions which use <tt>private</tt>.  To compensate for this, the module
also adds the option &lsquo;<tt>-P</tt>&rsquo; to the &lsquo;<tt>local</tt>&rsquo; builtin to declare private
parameters.
</p>
<p>For example, this construction fails if <tt>zsh/param/private</tt> has not yet
been loaded when &lsquo;<tt>bad_declaration</tt>&rsquo; is defined:
</p><div class="example">
<pre class="example">bad_declaration() {
  zmodload zsh/param/private
  private array=( one two three )
}
</pre></div>

<p>This construction works because <tt>local</tt> is already a keyword, and the
module is loaded before the statement is executed:
</p><div class="example">
<pre class="example">good_declaration() {
  zmodload zsh/param/private
  local -P array=( one two three )
}
</pre></div>

<p>The following is usable in scripts but may have trouble with <tt>autoload</tt>:
</p><div class="example">
<pre class="example">zmodload zsh/param/private
iffy_declaration() {
  private array=( one two three )
}
</pre></div>

<p>The <tt>private</tt> builtin may always be used with scalar assignments and
for declarations without assignments.
</p>
<p>Parameters declared with <tt>private</tt> have the following properties:
</p>
<ul>
<li> 
Within the function body where it is declared, the parameter
behaves as a local, except as noted above for tied or special parameters.
</li><li> 
The type of a parameter declared private cannot be changed in the
scope where it was declared, even if the parameter is unset.  Thus an
array cannot be assigned to a private scalar, etc.
</li><li> 
Within any other function called by the declaring function, the
private parameter does <em>NOT</em> hide other parameters of the same name, so
for example a global parameter of the same name is visible and may be
assigned or unset.  This includes calls to anonymous functions, although
that may also change in the future.
</li><li> 
An exported private remains in the environment of inner scopes but
appears unset for the current shell in those scopes.  Generally, exporting
private parameters should be avoided.
</li></ul>

<p>Note that this differs from the static scope defined by compiled languages
derived from C, in that the a new call to the same function creates a new
scope, i.e., the parameter is still associated with the call stack rather
than with the function definition.  It differs from ksh &lsquo;<tt>typeset -S</tt>&rsquo;
because the syntax used to define the function has no bearing on whether
the parameter scope is respected.
</p><hr>
<a name="The-zsh_002fregex-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fparam_002fprivate-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsched-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fregex-Module-1"></a>
<h2 class="section">22.23 The zsh/regex Module</h2>

<a name="index-regular-expressions"></a>
<a name="index-regex"></a>
<p>The <tt>zsh/regex</tt> module makes available the following test condition:
</p>
<dl compact="compact">
<dd><a name="index-regex_002dmatch"></a>
</dd>
<dt><var>expr</var> <tt>-regex-match</tt> <var>regex</var></dt>
<dd><p>Matches a string against a POSIX extended regular expression.
On successful match,
matched portion of the string will normally be placed in the <tt>MATCH</tt>
variable.  If there are any capturing parentheses within the regex, then
the <tt>match</tt> array variable will contain those.
If the match is not successful, then the variables will not be altered.
</p>
<p>For example,
</p>
<div class="example">
<pre class="example">[[ alphabetical -regex-match ^a([^a]+)a([^a]+)a ]] &amp;&amp;
print -l $MATCH X $match
</pre></div>

<p>If the option <tt>REMATCH_PCRE</tt> is not set, then the <tt>=~</tt> operator will
automatically load this module as needed and will invoke the
<tt>-regex-match</tt> operator.
</p>
<p>If <tt>BASH_REMATCH</tt> is set, then the array <tt>BASH_REMATCH</tt> will be set
instead of <tt>MATCH</tt> and <tt>match</tt>.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fsched-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fregex-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002fsocket-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fsched-Module-1"></a>
<h2 class="section">22.24 The zsh/sched Module</h2>

<p>The <tt>zsh/sched</tt> module makes available one builtin command and one
parameter.
</p>
<dl compact="compact">
<dd><a name="index-sched"></a>
<a name="index-timed-execution"></a>
<a name="index-execution_002c-timed"></a>
</dd>
<dt><tt>sched</tt> [<tt>-o</tt>] [<tt>+</tt>]<var>hh</var><tt>:</tt><var>mm</var>[<tt>:</tt><var>ss</var>] <var>command</var> ...</dt>
<dt><tt>sched</tt> [<tt>-o</tt>] [<tt>+</tt>]<var>seconds</var> <var>command</var> ...</dt>
<dt><tt>sched</tt> [ <tt>-</tt><var>item</var> ]</dt>
<dd><p>Make an entry in the scheduled list of commands to execute.
The time may be specified in either absolute or relative time,
and either as hours, minutes and (optionally) seconds separated by a
colon, or seconds alone.
An absolute number of seconds indicates the time since the epoch
(1970/01/01 00:00); this is useful in combination with the features in
the <tt>zsh/datetime</tt> module, see
<a href="#The-zsh_002fdatetime-Module">The zsh/datetime Module</a>.
</p>
<p>With no arguments, prints the list of scheduled commands.  If the
scheduled command has the <tt>-o</tt> flag set, this is shown at the
start of the command.
</p>
<p>With the argument &lsquo;<tt>-</tt><var>item</var>&rsquo;, removes the given item
from the list.  The numbering of the list is continuous and entries are
in time order, so the numbering can change when entries are added or
deleted.
</p>
<p>Commands are executed either immediately before a prompt, or while
the shell&rsquo;s line editor is waiting for input.  In the latter case
it is useful to be able to produce output that does not interfere
with the line being edited.  Providing the option <tt>-o</tt> causes
the shell to clear the command line before the event and redraw it
afterwards.  This should be used with any scheduled event that produces
visible output to the terminal; it is not needed, for example, with
output that updates a terminal emulator&rsquo;s title bar.
</p>
<p>To effect changes to the editor buffer when an event executes, use the
&lsquo;<tt>zle</tt>&rsquo; command with no arguments to test whether the editor is active,
and if it is, then use &lsquo;<tt>zle </tt><var>widget</var>&rsquo; to access the editor via
the named <var>widget</var>.
</p>
<p>The <tt>sched</tt> builtin is not made available by default when the shell
starts in a mode emulating another shell.  It can be made available
with the command &lsquo;<tt>zmodload -F zsh/sched b:sched</tt>&rsquo;.
</p>
</dd>
</dl>

<dl compact="compact">
<dd><a name="index-zsh_005fscheduled_005fevents"></a>
</dd>
<dt><tt>zsh_scheduled_events</tt></dt>
<dd><p>A readonly array corresponding to the events scheduled by the
<tt>sched</tt> builtin.  The indices of the array correspond to the numbers
shown when <tt>sched</tt> is run with no arguments (provided that the
<tt>KSH_ARRAYS</tt> option is not set).  The value of the array
consists of the scheduled time in seconds since the epoch
(see <a href="#The-zsh_002fdatetime-Module">The zsh/datetime Module</a> for facilities for
using this number), followed by a colon, followed by any options
(which may be empty but will be preceded by a &lsquo;<tt>-</tt>&rsquo; otherwise),
followed by a colon, followed by the command to be executed.
</p>
<p>The <tt>sched</tt> builtin should be used for manipulating the events.  Note
that this will have an immediate effect on the contents of the array,
so that indices may become invalid.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fnet_002fsocket-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsched-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Outbound-Connections-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fnet_002fsocket-Module-1"></a>
<h2 class="section">22.25 The zsh/net/socket Module</h2>

<p>The <tt>zsh/net/socket</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-zsocket"></a>
<a name="index-sockets"></a>
<a name="index-sockets_002c-Unix-domain"></a>
</dd>
<dt><tt>zsocket</tt> [ <tt>-altv</tt> ] [ <tt>-d</tt> <var>fd</var> ] [ <var>args</var> ]</dt>
<dd><p><tt>zsocket</tt> is implemented as a builtin to allow full use of shell
command line editing, file I/O, and job control mechanisms.
</p>
</dd>
</dl>


<hr>
<a name="Outbound-Connections-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002fsocket-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002fsocket-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Inbound-Connections-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.25.1 Outbound Connections</h3>
<a name="index-sockets_002c-outbound-Unix-domain"></a>

<dl compact="compact">
<dt><tt>zsocket</tt> [ <tt>-v</tt> ] [ <tt>-d</tt> <var>fd</var> ] <var>filename</var></dt>
<dd><p>Open a new Unix domain connection to <var>filename</var>.
The shell parameter <tt>REPLY</tt> will be set to the file descriptor
associated with that connection.  Currently, only stream connections
are supported.
</p>
<p>If <tt>-d</tt> is specified, its argument
will be taken as the target file descriptor for the
connection.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
<p>File descriptors can be closed with normal shell syntax when no longer
needed, for example:
</p>
<div class="example">
<pre class="example">exec {REPLY}&gt;&amp;-
</pre></div>

</dd>
</dl>


<hr>
<a name="Inbound-Connections-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Outbound-Connections-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002fsocket-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fstat-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.25.2 Inbound Connections</h3>
<a name="index-sockets_002c-inbound-Unix-domain"></a>

<dl compact="compact">
<dt><tt>zsocket</tt> <tt>-l</tt> [ <tt>-v</tt> ] [ <tt>-d</tt> <var>fd</var> ] <var>filename</var></dt>
<dd><p><tt>zsocket -l</tt> will open a socket listening on <var>filename</var>.
The shell parameter <tt>REPLY</tt> will be set to the file descriptor
associated with that listener.
</p>
<p>If <tt>-d</tt> is specified, its argument
will be taken as the target file descriptor for
the connection.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
<dt><tt>zsocket</tt> <tt>-a</tt> [ <tt>-tv</tt> ] [ <tt>-d</tt> <var>targetfd</var> ] <var>listenfd</var></dt>
<dd><p><tt>zsocket -a</tt> will accept an incoming connection
to the socket associated with <var>listenfd</var>.
The shell parameter <tt>REPLY</tt> will
be set to the file descriptor associated with
the inbound connection.
</p>
<p>If <tt>-d</tt> is specified, its argument
will be taken as the target file descriptor for the
connection.
</p>
<p>If <tt>-t</tt> is specified, <tt>zsocket</tt> will return
if no incoming connection is pending.  Otherwise
it will wait for one.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fstat-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Inbound-Connections-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsystem-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fstat-Module-1"></a>
<h2 class="section">22.26 The zsh/stat Module</h2>

<p>The <tt>zsh/stat</tt> module makes available one builtin command under
two possible names:
</p>
<dl compact="compact">
<dd><a name="index-zstat"></a>
<a name="index-stat"></a>
<a name="index-files_002c-listing"></a>
<a name="index-files_002c-examining"></a>

</dd>
<dt><tt>zstat </tt>[ <tt>-gnNolLtTrs</tt> ] [ <tt>-f</tt> <var>fd</var> ] [ <tt>-H</tt> <var>hash</var> ] [ <tt>-A</tt> <var>array</var> ] [ <tt>-F</tt> <var>fmt</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>[ <tt>+</tt><var>element</var> ] [ <var>file</var> ... ]</dt>
<dt><tt>stat</tt> <var>...</var></dt>
<dd><p>The command acts as a front end to the <tt>stat</tt> system call (see
man page stat(2)).  The same command is provided with two names; as
the name <tt>stat</tt> is often used by an external command it is recommended
that only the <tt>zstat</tt> form of the command is used.  This can be
arranged by loading the module with the command &lsquo;<tt>zmodload -F zsh/stat
b:zstat</tt>&rsquo;.
</p>
<p>If the <tt>stat</tt> call fails, the appropriate system error message
printed and status 1 is returned.
The fields of <tt>struct stat</tt> give information about
the files provided as arguments to the command.  In addition to those
available from the <tt>stat</tt> call, an extra element &lsquo;<tt>link</tt>&rsquo; is provided.
These elements are:
</p>
<dl compact="compact">
<dt><tt>device</tt></dt>
<dd><p>The number of the device on which the file resides.
</p>
</dd>
<dt><tt>inode</tt></dt>
<dd><p>The unique number of the file on this device (&lsquo;<em>inode</em>&rsquo; number).
</p>
</dd>
<dt><tt>mode</tt></dt>
<dd><p>The mode of the file; that is, the file&rsquo;s type and access permissions.
With the <tt>-s</tt> option, this will
be returned as a string corresponding to the first column in the
display of the <tt>ls -l</tt> command.
</p>
</dd>
<dt><tt>nlink</tt></dt>
<dd><p>The number of hard links to the file.
</p>
</dd>
<dt><tt>uid</tt></dt>
<dd><p>The user ID of the owner of the file.  With the <tt>-s</tt>
option, this is displayed as a user name.
</p>
</dd>
<dt><tt>gid</tt></dt>
<dd><p>The group ID of the file.  With the <tt>-s</tt> option, this
is displayed as a group name.
</p>
</dd>
<dt><tt>rdev</tt></dt>
<dd><p>The raw device number.  This is only useful for special devices.
</p>
</dd>
<dt><tt>size</tt></dt>
<dd><p>The size of the file in bytes.
</p>
</dd>
<dt><tt>atime</tt></dt>
<dt><tt>mtime</tt></dt>
<dt><tt>ctime</tt></dt>
<dd><p>The last access, modification and inode change times
of the file, respectively, as the number of seconds since
midnight GMT on 1st January, 1970.  With the <tt>-s</tt> option,
these are printed as strings for the local time zone; the format
can be altered with the <tt>-F</tt> option, and with the <tt>-g</tt>
option the times are in GMT.
</p>
</dd>
<dt><tt>blksize</tt></dt>
<dd><p>The number of bytes in one allocation block on the
device on which the file resides.
</p>
</dd>
<dt><tt>block</tt></dt>
<dd><p>The number of disk blocks used by the file.
</p>
</dd>
<dt><tt>link</tt></dt>
<dd><p>If the file is a link and the <tt>-L</tt> option is in
effect, this contains the name of the file linked to, otherwise
it is empty.  Note that if this element is selected (&lsquo;&lsquo;<tt>zstat +link</tt>&rsquo;&rsquo;)
then the <tt>-L</tt> option is automatically used.
</p>
</dd>
</dl>

<p>A particular element may be selected by including its name
preceded by a &lsquo;<tt>+</tt>&rsquo; in the option list; only one element is allowed.
The element may be shortened to any unique set of leading
characters.  Otherwise, all elements will be shown for all files.
</p>
<p>Options:
</p>
<dl compact="compact">
<dt><tt>-A</tt> <var>array</var></dt>
<dd><p>Instead of displaying the results on standard
output, assign them to an <var>array</var>, one <tt>struct stat</tt> element per array
element for each file in order.  In this case neither the name
of the element nor the name of the files appears in <var>array</var> unless the
<tt>-t</tt> or <tt>-n</tt> options were given, respectively.  If <tt>-t</tt> is given,
the element name appears as a prefix to the
appropriate array element; if <tt>-n</tt> is given, the file name
appears as a separate array element preceding all the others.
Other formatting options are respected.
</p>
</dd>
<dt><tt>-H</tt> <var>hash</var></dt>
<dd><p>Similar to <tt>-A</tt>, but instead assign the values to <var>hash</var>.  The keys
are the elements listed above.  If the <tt>-n</tt> option is provided then the
name of the file is included in the hash with key <tt>name</tt>.
</p>
</dd>
<dt><tt>-f</tt> <var>fd</var></dt>
<dd><p>Use the file on file descriptor <var>fd</var> instead of
named files; no list of file names is allowed in this case.
</p>
</dd>
<dt><tt>-F</tt> <var>fmt</var></dt>
<dd><p>Supplies a <tt>strftime</tt> (see man page strftime(3)) string for the
formatting of the time elements.  The format string supports all of the
zsh extensions described in
<a href="Prompt-Expansion.html#Prompt-Expansion">Prompt Expansion</a>.
The <tt>-s</tt> option is implied.
</p>
</dd>
<dt><tt>-g</tt></dt>
<dd><p>Show the time elements in the GMT time zone.  The
<tt>-s</tt> option is implied.
</p>
</dd>
<dt><tt>-l</tt></dt>
<dd><p>List the names of the type elements (to standard
output or an array as appropriate) and return immediately;
arguments, and options other than <tt>-A</tt>, are ignored.
</p>
</dd>
<dt><tt>-L</tt></dt>
<dd><p>Perform an <tt>lstat</tt> (see man page lstat(2)) rather than a <tt>stat</tt>
system call.  In this case, if the file is a link, information
about the link itself rather than the target file is returned.
This option is required to make the <tt>link</tt> element useful.
It&rsquo;s important to note that this is the exact opposite from man page ls(1),
etc.
</p>
</dd>
<dt><tt>-n</tt></dt>
<dd><p>Always show the names of files.  Usually these are
only shown when output is to standard output and there is more
than one file in the list.
</p>
</dd>
<dt><tt>-N</tt></dt>
<dd><p>Never show the names of files.
</p>
</dd>
<dt><tt>-o</tt></dt>
<dd><p>If a raw file mode is printed, show it in octal, which is more useful for
human consumption than the default of decimal.  A leading zero will be
printed in this case.  Note that this does not affect whether a raw or
formatted file mode is shown, which is controlled by the <tt>-r</tt> and <tt>-s</tt>
options, nor whether a mode is shown at all.
</p>
</dd>
<dt><tt>-r</tt></dt>
<dd><p>Print raw data (the default format) alongside string
data (the <tt>-s</tt> format); the string data appears in parentheses
after the raw data.
</p>
</dd>
<dt><tt>-s</tt></dt>
<dd><p>Print <tt>mode</tt>, <tt>uid</tt>, <tt>gid</tt> and the three time
elements as strings instead of numbers.  In each case the format
is like that of <tt>ls -l</tt>.
</p>
</dd>
<dt><tt>-t</tt></dt>
<dd><p>Always show the type names for the elements of
<tt>struct stat</tt>.  Usually these are only shown when output is to
standard output and no individual element has been selected.
</p>
</dd>
<dt><tt>-T</tt></dt>
<dd><p>Never show the type names of the <tt>struct stat</tt> elements.
</p>
</dd>
</dl>

</dd>
</dl>
<hr>
<a name="The-zsh_002fsystem-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fstat-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Builtins" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fsystem-Module-1"></a>
<h2 class="section">22.27 The zsh/system Module</h2>

<p>The <tt>zsh/system</tt> module makes available various builtin commands and
parameters.
</p>

<hr>
<a name="Builtins"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsystem-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsystem-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Math-Functions" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.27.1 Builtins</h3>

<dl compact="compact">
<dd><a name="index-syserror"></a>
</dd>
<dt><tt>syserror</tt> [ <tt>-e</tt> <var>errvar</var> ] [ <tt>-p</tt> <var>prefix</var> ] [ <var>errno</var> | <var>errname</var> ]</dt>
<dd><p>This command prints out the error message associated with <var>errno</var>, a
system error number, followed by a newline to standard error.
</p>
<p>Instead of the error number, a name <var>errname</var>, for example
<tt>ENOENT</tt>, may be used.  The set of names is the same as the contents
of the array <tt>errnos</tt>, see below.
</p>
<p>If the string <var>prefix</var> is given, it is printed in front of the error
message, with no intervening space.
</p>
<p>If <var>errvar</var> is supplied, the entire message, without a newline, is
assigned to the parameter names <var>errvar</var> and nothing is output.
</p>
<p>A return status of 0 indicates the message was successfully printed
(although it may not be useful if the error number was out of the
system&rsquo;s range), a return status of 1 indicates an error in the
parameters, and a return status of 2 indicates the error name was
not recognised (no message is printed for this).
</p>
<a name="index-sysopen"></a>

</dd>
<dt><tt>sysopen</tt> [ <tt>-arw</tt> ] [ <tt>-m</tt> <var>permissions</var> ] [ <tt>-o</tt> <var>options</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt><tt>-u</tt> <var>fd</var> <var>file</var></dt>
<dd><p>This command opens a file. The <tt>-r</tt>, <tt>-w</tt> and <tt>-a</tt> flags indicate
whether the file should be opened for reading, writing and appending,
respectively. The <tt>-m</tt> option allows the initial permissions to use when
creating a file to be specified in octal form.  The file descriptor is
specified with <tt>-u</tt>. Either an explicit file descriptor in the range 0 to 9 can
be specified or a variable name can be given to which the file descriptor
number will be assigned.
</p>
<p>The <tt>-o</tt> option allows various system specific options to be
specified as a comma-separated list. The following is a list of possible
options. Note that, depending on the system, some may not be available.
</p><dl compact="compact">
<dt><tt>cloexec</tt></dt>
<dd><p>mark file to be closed when other programs are executed
</p>
</dd>
<dt><tt>create</tt></dt>
<dt><tt>creat</tt></dt>
<dd><p>create file if it does not exist
</p>
</dd>
<dt><tt>excl</tt></dt>
<dd><p>create file, error if it already exists
</p>
</dd>
<dt><tt>noatime</tt></dt>
<dd><p>suppress updating of the file atime
</p>
</dd>
<dt><tt>nofollow</tt></dt>
<dd><p>fail if <var>file</var> is a symbolic link
</p>
</dd>
<dt><tt>sync</tt></dt>
<dd><p>request that writes wait until data has been physically written
</p>
</dd>
<dt><tt>truncate</tt></dt>
<dt><tt>trunc</tt></dt>
<dd><p>truncate file to size 0
</p>
</dd>
</dl>

<p>To close the file, use one of the following:
</p>
<div class="example">
<pre class="example"><tt>exec {</tt><var>fd</var><tt>}&lt;&amp;-</tt>
<tt>exec {</tt><var>fd</var><tt>}&gt;&amp;-</tt>
</pre></div>

<a name="index-sysread"></a>

</dd>
<dt><tt>sysread </tt>[ <tt>-c</tt> <var>countvar</var> ] [ <tt>-i</tt> <var>infd</var> ] [ <tt>-o</tt> <var>outfd</var> ]</dt>
<dt><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt>[ <tt>-s</tt> <var>bufsize</var> ] [ <tt>-t</tt> <var>timeout</var> ] [ <var>param</var> ]</dt>
<dd><p>Perform a single system read from file descriptor <var>infd</var>, or zero if
that is not given.  The result of the read is stored in <var>param</var> or
<tt>REPLY</tt> if that is not given.  If <var>countvar</var> is given, the number
of bytes read is assigned to the parameter named by <var>countvar</var>.
</p>
<p>The maximum number of bytes read is <var>bufsize</var> or 8192 if that is not
given, however the command returns as soon as any number of bytes was
successfully read.
</p>
<p>If <var>timeout</var> is given, it specifies a timeout in seconds, which may
be zero to poll the file descriptor.  This is handled by the <tt>poll</tt>
system call if available, otherwise the <tt>select</tt> system call if
available.
</p>
<p>If <var>outfd</var> is given, an attempt is made to write all the bytes just
read to the file descriptor <var>outfd</var>.  If this fails, because of a
system error other than <tt>EINTR</tt> or because of an internal zsh error
during an interrupt, the bytes read but not written are stored in the
parameter named by <var>param</var> if supplied (no default is used in this
case), and the number of bytes read but not written is stored in the
parameter named by <var>countvar</var> if that is supplied.  If it was
successful, <var>countvar</var> contains the full number of bytes transferred,
as usual, and <var>param</var> is not set.
</p>
<p>The error <tt>EINTR</tt> (interrupted system call) is handled internally so
that shell interrupts are transparent to the caller.  Any other error
causes a return.
</p>
<p>The possible return statuses are
</p><dl compact="compact">
<dt>0</dt>
<dd><p>At least one byte of data was successfully read and, if appropriate,
written.
</p>
</dd>
<dt>1</dt>
<dd><p>There was an error in the parameters to the command.  This is the only
error for which a message is printed to standard error.
</p>
</dd>
<dt>2</dt>
<dd><p>There was an error on the read, or on polling the input file descriptor
for a timeout.  The parameter <tt>ERRNO</tt> gives the error.
</p>
</dd>
<dt>3</dt>
<dd><p>Data were successfully read, but there was an error writing them
to <var>outfd</var>.  The parameter <tt>ERRNO</tt> gives the error.
</p>
</dd>
<dt>4</dt>
<dd><p>The attempt to read timed out.  Note this does not set <tt>ERRNO</tt> as this
is not a system error.
</p>
</dd>
<dt>5</dt>
<dd><p>No system error occurred, but zero bytes were read.  This usually
indicates end of file.  The parameters are set according to the
usual rules; no write to <var>outfd</var> is attempted.
</p>
</dd>
</dl>

</dd>
<dt><tt>sysseek</tt> [ <tt>-u</tt> <var>fd</var> ] [ <tt>-w</tt> <tt>start</tt>|<tt>end</tt>|<tt>current</tt> ] <var>offset</var></dt>
<dd><p>The current file position at which future reads and writes will take place is
adjusted to the specified byte offset. The <var>offset</var> is evaluated as a math
expression. The <tt>-u</tt> option allows the file descriptor to be specified. By
default the offset is specified relative to the start or the file but, with the
<tt>-w</tt> option, it is possible to specify that the offset should be relative to
the current position or the end of the file.
</p>
</dd>
<dt><tt>syswrite</tt> [ <tt>-c</tt> <var>countvar</var> ] [ <tt>-o</tt> <var>outfd</var> ] <var>data</var></dt>
<dd><p>The data (a single string of bytes) are written to the file descriptor
<var>outfd</var>, or 1 if that is not given, using the <tt>write</tt> system call.
Multiple write operations may be used if the first does not write all
the data.
</p>
<p>If <var>countvar</var> is given, the number of byte written is stored in the
parameter named by <var>countvar</var>; this may not be the full length of
<var>data</var> if an error occurred.
</p>
<p>The error <tt>EINTR</tt> (interrupted system call) is handled internally by
retrying; otherwise an error causes the command to return.  For example,
if the file descriptor is set to non-blocking output, an error
<tt>EAGAIN</tt> (on some systems, <tt>EWOULDBLOCK</tt>) may result in the command
returning early.
</p>
<p>The return status may be 0 for success, 1 for an error in the parameters
to the command, or 2 for an error on the write; no error message is
printed in the last case, but the parameter <tt>ERRNO</tt> will reflect
the error that occurred.
</p>
</dd>
<dt><tt>zsystem flock</tt> [ <tt>-t</tt> <var>timeout</var> ] [ <tt>-f</tt> <var>var</var> ] [<tt>-er</tt>] <var>file</var></dt>
<dt><tt>zsystem flock -u</tt> <var>fd_expr</var></dt>
<dd><p>The builtin <tt>zsystem</tt>&rsquo;s subcommand <tt>flock</tt> performs advisory file
locking (via the man page fcntl(2) system call) over the entire contents
of the given file.  This form of locking requires the processes
accessing the file to cooperate; its most obvious use is between two
instances of the shell itself.
</p>
<p>In the first form the named <var>file</var>, which must already exist, is
locked by opening a file descriptor to the file and applying a lock to
the file descriptor.  The lock terminates when the shell process that
created the lock exits; it is therefore often convenient to create file
locks within subshells, since the lock is automatically released when
the subshell exits.  Status 0 is returned if the lock succeeds, else
status 1.
</p>
<p>In the second form the file descriptor given by the arithmetic
expression <var>fd_expr</var> is closed, releasing a lock.  The file descriptor
can be queried by using the &lsquo;<tt>-f</tt> <var>var</var>&rsquo; form during the lock;
on a successful lock, the shell variable <var>var</var> is set to the file
descriptor used for locking.  The lock will be released if the
file descriptor is closed by any other means, for example using
&lsquo;<tt>exec {</tt><var>var</var><tt>}&gt;&amp;-</tt>&rsquo;; however, the form described here performs
a safety check that the file descriptor is in use for file locking.
</p>
<p>By default the shell waits indefinitely for the lock to succeed.
The option <tt>-t</tt> <var>timeout</var> specifies a timeout for the lock in
seconds; currently this must be an integer.  The shell will attempt
to lock the file once a second during this period.  If the attempt
times out, status 2 is returned.
</p>
<p>If the option <tt>-e</tt> is given, the file descriptor for the lock is
preserved when the shell uses <tt>exec</tt> to start a new process;
otherwise it is closed at that point and the lock released.
</p>
<p>If the option <tt>-r</tt> is given, the lock is only for reading, otherwise
it is for reading and writing.  The file descriptor is opened
accordingly.
</p>
</dd>
<dt><tt>zsystem supports</tt> <var>subcommand</var></dt>
<dd><p>The builtin <tt>zsystem</tt>&rsquo;s subcommand <tt>supports</tt> tests whether a
given subcommand is supported.  It returns status 0 if so, else
status 1.  It operates silently unless there was a syntax error
(i.e. the wrong number of arguments), in which case status 255
is returned.  Status 1 can indicate one of two things:  <var>subcommand</var>
is known but not supported by the current operating system, or
<var>subcommand</var> is not known (possibly because this is an older
version of the shell before it was implemented).
</p>
</dd>
</dl>


<hr>
<a name="Math-Functions"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Builtins" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsystem-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-3" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.27.2 Math Functions</h3>

<dl compact="compact">
<dt><tt>systell(<var>fd</var>)</tt></dt>
<dd><p>The systell math function returns the current file position for the file
descriptor passed as an argument.
</p>
</dd>
</dl>


<hr>
<a name="Parameters-3"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Math-Functions" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fsystem-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.27.3 Parameters</h3>

<dl compact="compact">
<dd><a name="index-errnos"></a>
</dd>
<dt><tt>errnos</tt></dt>
<dd><p>A readonly array of the names of errors defined on the system.  These
are typically macros defined in C by including the system header file
<tt>errno.h</tt>.  The index of each name (assuming the option <tt>KSH_ARRAYS</tt>
is unset) corresponds to the error number.  Error numbers <var>num</var>
before the last known error which have no name are given the name
<tt>E</tt><var>num</var> in the array.
</p>
<p>Note that aliases for errors are not handled; only the canonical name is
used.
</p>
<a name="index-sysparams"></a>
</dd>
<dt><tt>sysparams</tt></dt>
<dd><p>A readonly associative array.  The keys are:
</p>
<dl compact="compact">
<dt><tt>pid</tt></dt>
<dd><a name="index-pid_002c-sysparams"></a>
<p>Returns the process ID of the current process, even in subshells.  Compare
<tt>$$</tt>, which returns the process ID of the main shell process.
</p>
</dd>
<dt><tt>ppid</tt></dt>
<dd><a name="index-ppid_002c-sysparams"></a>
<p>Returns the process ID of the parent of the current process, even in
subshells.  Compare <tt>$PPID</tt>, which returns the process ID of the parent
of the main shell process.
</p>
</dd>
<dt><tt>procsubstpid</tt></dt>
<dd><p>Returns the process ID of the last process started for process
substitution, i.e. the <tt>&lt;(</tt><var>...</var><tt>)</tt> and
<tt>&gt;(</tt><var>...</var><tt>)</tt> expansions.
</p>
</dd>
</dl>

</dd>
</dl>
<hr>
<a name="The-zsh_002fnet_002ftcp-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-3" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Outbound-Connections" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fnet_002ftcp-Module-1"></a>
<h2 class="section">22.28 The zsh/net/tcp Module</h2>

<p>The <tt>zsh/net/tcp</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-ztcp"></a>
<a name="index-TCP"></a>
<a name="index-sockets_002c-TCP"></a>
</dd>
<dt><tt>ztcp</tt> [ <tt>-acflLtv</tt> ] [ <tt>-d</tt> <var>fd</var> ] [ <var>args</var> ]</dt>
<dd><p><tt>ztcp</tt> is implemented as a builtin to allow full use of shell
command line editing, file I/O, and job control mechanisms.
</p>
<p>If <tt>ztcp</tt> is run with no options, it will output
the contents of its session table.
</p>
<p>If it is run with only the option <tt>-L</tt>, it will output the contents of
the session table in a format suitable for automatic parsing.  The option
is ignored if given with a command to open or close a session.  The output
consists of a set of lines, one per session, each containing the following
elements separated by spaces:
</p>
<dl compact="compact">
<dt>File descriptor</dt>
<dd><p>The file descriptor in use for the connection.  For normal inbound (<tt>I</tt>)
and outbound (<tt>O</tt>) connections this may be read and written by the usual
shell mechanisms.  However, it should only be close with &lsquo;<tt>ztcp -c</tt>&rsquo;.
</p>
</dd>
<dt>Connection type</dt>
<dd><p>A letter indicating how the session was created:
</p>
<dl compact="compact">
<dt><tt>Z</tt></dt>
<dd><p>A session created with the <tt>zftp</tt> command.
</p>
</dd>
<dt><tt>L</tt></dt>
<dd><p>A connection opened for listening with &lsquo;<tt>ztcp -l</tt>&rsquo;.
</p>
</dd>
<dt><tt>I</tt></dt>
<dd><p>An inbound connection accepted with &lsquo;<tt>ztcp -a</tt>&rsquo;.
</p>
</dd>
<dt><tt>O</tt></dt>
<dd><p>An outbound connection created with &lsquo;<tt>ztcp</tt> <var>host</var> <var>...</var>&rsquo;.
</p>
</dd>
</dl>


</dd>
<dt>The local host</dt>
<dd><p>This is usually set to an all-zero IP address as the address of the
localhost is irrelevant.
</p>
</dd>
<dt>The local port</dt>
<dd><p>This is likely to be zero unless the connection is for listening.
</p>
</dd>
<dt>The remote host</dt>
<dd><p>This is the fully qualified domain name of the peer, if available, else an
IP address.  It is an all-zero IP address for a session opened for
listening.
</p>
</dd>
<dt>The remote port</dt>
<dd><p>This is zero for a connection opened for listening.
</p>
</dd>
</dl>

</dd>
</dl>


<hr>
<a name="Outbound-Connections"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Inbound-Connections" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.28.1 Outbound Connections</h3>
<a name="index-sockets_002c-outbound-TCP"></a>

<dl compact="compact">
<dt><tt>ztcp</tt> [ <tt>-v</tt> ] [ <tt>-d</tt> <var>fd</var> ] <var>host</var> [ <var>port</var> ]</dt>
<dd><p>Open a new TCP connection to <var>host</var>.  If the <var>port</var> is
omitted, it will default to port 23.  The connection will
be added to the session table and the shell parameter
<tt>REPLY</tt> will be set to the file descriptor associated
with that connection.
</p>
<p>If <tt>-d</tt> is specified, its argument will be taken as the target file
descriptor for the connection.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
</dl>


<hr>
<a name="Inbound-Connections"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Outbound-Connections" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Closing-Connections" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.28.2 Inbound Connections</h3>
<a name="index-sockets_002c-inbound-TCP"></a>

<dl compact="compact">
<dt><tt>ztcp</tt> <tt>-l</tt> [ <tt>-v</tt> ] [ <tt>-d</tt> <var>fd</var> ] <var>port</var></dt>
<dd><p><tt>ztcp -l</tt> will open a socket listening on TCP
<var>port</var>.  The socket will be added to the
session table and the shell parameter <tt>REPLY</tt>
will be set to the file descriptor associated
with that listener.
</p>
<p>If <tt>-d</tt> is specified, its argument will be taken as the target file
descriptor for the connection.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
<dt><tt>ztcp</tt> <tt>-a</tt> [ <tt>-tv</tt> ] [ <tt>-d</tt> <var>targetfd</var> ] <var>listenfd</var></dt>
<dd><p><tt>ztcp -a</tt> will accept an incoming connection
to the port associated with <var>listenfd</var>.
The connection will be added to the session
table and the shell parameter <tt>REPLY</tt> will
be set to the file descriptor associated with
the inbound connection.
</p>
<p>If <tt>-d</tt> is specified, its argument
will be taken as the target file descriptor for the
connection.
</p>
<p>If <tt>-t</tt> is specified, <tt>ztcp</tt> will return
if no incoming connection is pending.  Otherwise
it will wait for one.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
</dl>


<hr>
<a name="Closing-Connections"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Inbound-Connections" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Example-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.28.3 Closing Connections</h3>
<a name="index-sockets_002c-closing-TCP"></a>

<dl compact="compact">
<dt><tt>ztcp</tt> <tt>-cf</tt> [ <tt>-v</tt> ] [ <var>fd</var> ]</dt>
<dt><tt>ztcp</tt> <tt>-c</tt> [ <tt>-v</tt> ] [ <var>fd</var> ]</dt>
<dd><p><tt>ztcp -c</tt> will close the socket associated
with <var>fd</var>.  The socket will be removed from the
session table.  If <var>fd</var> is not specified,
<tt>ztcp</tt> will close everything in the session table.
</p>
<p>Normally, sockets registered by zftp (see
<a href="#The-zsh_002fzftp-Module">The zsh/zftp Module</a>
) cannot be closed this way.  In order
to force such a socket closed, use <tt>-f</tt>.
</p>
<p>In order to elicit more verbose output, use <tt>-v</tt>.
</p>
</dd>
</dl>


<hr>
<a name="Example-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Closing-Connections" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fnet_002ftcp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002ftermcap-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.28.4 Example</h3>
<a name="index-TCP_002c-example"></a>
<p>Here is how to create a TCP connection between two instances of zsh.  We
need to pick an unassigned port; here we use the randomly chosen 5123.
</p>
<p>On <tt>host1</tt>,
</p><div class="example">
<pre class="example">zmodload zsh/net/tcp
ztcp -l 5123
listenfd=$REPLY
ztcp -a $listenfd
fd=$REPLY
</pre></div>
<p>The second from last command blocks until there is an incoming connection.
</p>
<p>Now create a connection from <tt>host2</tt> (which may, of course, be the same
machine):
</p><div class="example">
<pre class="example">zmodload zsh/net/tcp
ztcp host1 5123
fd=$REPLY
</pre></div>

<p>Now on each host, <tt>$fd</tt> contains a file descriptor for talking to the
other.  For example, on <tt>host1</tt>:
</p><div class="example">
<pre class="example">print This is a message &gt;&amp;$fd
</pre></div>
<p>and on <tt>host2</tt>:
</p><div class="example">
<pre class="example">read -r line &lt;&amp;$fd; print -r - $line
</pre></div>
<p>prints &lsquo;<tt>This is a message</tt>&rsquo;.
</p>
<p>To tidy up, on <tt>host1</tt>:
</p><div class="example">
<pre class="example">ztcp -c $listenfd
ztcp -c $fd
</pre></div>
<p>and on <tt>host2</tt>
</p><div class="example">
<pre class="example">ztcp -c $fd
</pre></div>
<hr>
<a name="The-zsh_002ftermcap-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Example-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fterminfo-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002ftermcap-Module-1"></a>
<h2 class="section">22.29 The zsh/termcap Module</h2>

<p>The <tt>zsh/termcap</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-echotc"></a>
<a name="index-termcap-value_002c-printing"></a>
</dd>
<dt><tt>echotc</tt> <var>cap</var> [ <var>arg</var> ... ]</dt>
<dd><p>Output the termcap value corresponding to the capability
<var>cap</var>, with optional arguments.
</p>
</dd>
</dl>

<p>The <tt>zsh/termcap</tt> module makes available one parameter:
</p>
<dl compact="compact">
<dd><a name="index-termcap"></a>
</dd>
<dt><tt>termcap</tt></dt>
<dd><p>An associative array that maps termcap capability codes to
their values.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fterminfo-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002ftermcap-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fterminfo-Module-1"></a>
<h2 class="section">22.30 The zsh/terminfo Module</h2>

<p>The <tt>zsh/terminfo</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-echoti"></a>
<a name="index-terminfo-value_002c-printing"></a>
</dd>
<dt><tt>echoti</tt> <var>cap</var> [ <var>arg</var> ]</dt>
<dd><p>Output the terminfo value corresponding to the capability
<var>cap</var>, instantiated with <var>arg</var> if applicable.
</p>
</dd>
</dl>

<p>The <tt>zsh/terminfo</tt> module makes available one parameter:
</p>
<dl compact="compact">
<dd><a name="index-terminfo"></a>
</dd>
<dt><tt>terminfo</tt></dt>
<dd><p>An associative array that maps terminfo capability names to
their values.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fzftp-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fterminfo-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Subcommands" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzftp-Module-1"></a>
<h2 class="section">22.31 The zsh/zftp Module</h2>

<p>The <tt>zsh/zftp</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-zftp"></a>
<a name="index-FTP"></a>
<a name="index-files_002c-transferring"></a>
</dd>
<dt><tt>zftp</tt> <var>subcommand</var> [ <var>args</var> ]</dt>
<dd><p>The <tt>zsh/zftp</tt> module is a client for FTP (file transfer protocol).  It
is implemented as a builtin to allow full use of shell command line
editing, file I/O, and job control mechanisms.  Often, users will
access it via shell functions providing a more powerful interface; a set is
provided with the <tt>zsh</tt> distribution and is described in
<a href="Zftp-Function-System.html#Zftp-Function-System">Zftp Function System</a>.  However, the <tt>zftp</tt> command is entirely usable in its
own right.
</p>
<p>All commands consist of the command name <tt>zftp</tt> followed by the name
of a subcommand.  These are listed below.  The return status of each
subcommand is supposed to reflect the success or failure of the remote
operation.  See a description of the variable <tt>ZFTP_VERBOSE</tt> for
more information on how responses from the server may be printed.
</p>
</dd>
</dl>


<hr>
<a name="Subcommands"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.31.1 Subcommands</h3>
<a name="index-zftp_002c-subcommands"></a>

<dl compact="compact">
<dd><a name="index-FTP_002c-starting-a-session"></a>
</dd>
<dt><tt>open</tt> <var>host</var>[<tt>:</tt><var>port</var>] [ <var>user</var> [ <var>password</var> [ <var>account</var> ] ] ]</dt>
<dd><p>Open a new FTP session to <var>host</var>, which may be the name of a TCP/IP
connected host or an IP number in the standard dot notation.  If the
argument is in the form <var>host</var><tt>:</tt><var>port</var>, open a connection to
TCP port <var>port</var> instead of the standard FTP port 21.  This may be
the name of a TCP service or a number:  see the description of
<tt>ZFTP_PORT</tt> below for more information.
</p>
<p>If IPv6 addresses in colon format are used, the <var>host</var> should be
surrounded by quoted square brackets to distinguish it from the <var>port</var>,
for example <tt>&rsquo;[fe80::203:baff:fe02:8b56]&rsquo;</tt>.  For consistency this is
allowed with all forms of <var>host</var>.
</p>
<p>Remaining arguments are passed to the <tt>login</tt> subcommand.  Note that
if no arguments beyond <var>host</var> are supplied, <tt>open</tt> will <em>not</em>
automatically call <tt>login</tt>.  If no arguments at all are supplied,
<tt>open</tt> will use the parameters set by the <tt>params</tt> subcommand.
</p>
<p>After a successful open, the shell variables <tt>ZFTP_HOST</tt>, <tt>ZFTP_PORT</tt>,
<tt>ZFTP_IP</tt> and <tt>ZFTP_SYSTEM</tt> are available; see &lsquo;Variables&rsquo;
below.
</p>
</dd>
<dt><tt>login</tt> [ <var>name</var> [ <var>password</var> [ <var>account</var> ] ] ]</dt>
<dt><tt>user</tt> [ <var>name</var> [ <var>password</var> [ <var>account</var> ] ] ]</dt>
<dd><p>Login the user <var>name</var> with parameters <var>password</var> and <var>account</var>.
Any of the parameters can be omitted, and will be read from standard
input if needed (<var>name</var> is always needed).  If 
standard input is a terminal, a prompt for each one will be printed on
standard error and <var>password</var> will not be echoed.  If any of the
parameters are not used, a warning message is printed.
</p>
<p>After a successful login, the shell variables <tt>ZFTP_USER</tt>,
<tt>ZFTP_ACCOUNT</tt> and <tt>ZFTP_PWD</tt> are available; see &lsquo;Variables&rsquo;
below.
</p>
<p>This command may be re-issued when a user is already logged in, and
the server will first be reinitialized for a new user.
</p>
</dd>
<dt><tt>params</tt> [ <var>host</var> [ <var>user</var> [ <var>password</var> [ <var>account</var> ] ] ] ]</dt>
<dt><tt>params</tt> <tt>-</tt></dt>
<dd><p>Store the given parameters for a later <tt>open</tt> command with no
arguments.  Only those given on the command line will be remembered.
If no arguments are given, the parameters currently set are printed,
although the password will appear as a line of stars; the return status is
one if no parameters were set, zero otherwise.
</p>
<p>Any of the parameters may be specified as a &lsquo;<tt>?</tt>&rsquo;, which
may need to be quoted to protect it from shell expansion.  In this case,
the appropriate parameter will be read from stdin as with the
<tt>login</tt> subcommand, including special handling of <var>password</var>.  If the
&lsquo;<tt>?</tt>&rsquo; is followed by a string, that is used as the prompt for reading the
parameter instead of the default message (any necessary punctuation and
whitespace should be included at the end of the prompt).  The first letter
of the parameter (only) may be quoted with a &lsquo;<tt>\</tt>&rsquo;; hence an argument
<tt>&quot;\\$word&quot;</tt> guarantees that the string from the shell parameter <tt>$word</tt>
will be treated literally, whether or not it begins with a &lsquo;<tt>?</tt>&rsquo;.
</p>
<p>If instead a single &lsquo;<tt>-</tt>&rsquo; is given, the existing parameters, if any,
are deleted.  In that case, calling <tt>open</tt> with no arguments will
cause an error.
</p>
<p>The list of parameters is not deleted after a <tt>close</tt>, however it
will be deleted if the <tt>zsh/zftp</tt> module is unloaded.
</p>
<p>For example,
</p>
<div class="example">
<pre class="example">zftp params ftp.elsewhere.xx juser '?Password for juser: '
</pre></div>

<p>will store the host <tt>ftp.elsewhere.xx</tt> and the user <tt>juser</tt> and
then prompt the user for the corresponding password with the given prompt.
</p>
</dd>
<dt><tt>test</tt></dt>
<dd><p>Test the connection; if the server has reported
that it has closed the connection (maybe due to a timeout), return
status 2; if no connection was open anyway, return status 1; else
return status 0.  The <tt>test</tt> subcommand is
silent, apart from messages printed by the <tt>$ZFTP_VERBOSE</tt>
mechanism, or error messages if the connection closes.  There is no
network overhead for this test.
</p>
<p>The test is only supported on systems with either the
<tt>select(2)</tt> or
<tt>poll(2)</tt> system calls; otherwise the message &lsquo;<tt>not
supported on this system</tt>&rsquo; is printed instead.
</p>
<p>The <tt>test</tt> subcommand will automatically be called at the start of any
other subcommand for the current session when a connection is open.
</p>
</dd>
<dt><tt>cd</tt> <var>directory</var></dt>
<dd><p>Change the remote directory to <var>directory</var>.  Also alters the shell
variable <tt>ZFTP_PWD</tt>.
</p>
</dd>
<dt><tt>cdup</tt></dt>
<dd><p>Change the remote directory to the one higher in the directory tree.
Note that <tt>cd ..</tt> will also work correctly on non-UNIX systems.
</p>
</dd>
<dt><tt>dir</tt> [ <var>arg</var> ... ]</dt>
<dd><p>Give a (verbose) listing of the remote directory.  The <var>arg</var>s are
passed directly to the server. The command&rsquo;s behaviour is implementation
dependent, but a UNIX server will typically interpret <var>arg</var>s as
arguments to the <tt>ls</tt> command and with no arguments return the
result of &lsquo;<tt>ls -l</tt>&rsquo;. The directory is listed to standard output.
</p>
</dd>
<dt><tt>ls</tt> [ <var>arg</var> ... ]</dt>
<dd><p>Give a (short) listing of the remote directory.  With no <var>arg</var>,
produces a raw list of the files in the directory, one per line.
Otherwise, up to vagaries of the server implementation, behaves
similar to <tt>dir</tt>.
</p>
</dd>
<dt><tt>type</tt> [ <var>type</var> ]</dt>
<dd><p>Change the type for the transfer to <var>type</var>, or print the current type
if <var>type</var> is absent.  The allowed values are &lsquo;<tt>A</tt>&rsquo; (ASCII),
&lsquo;<tt>I</tt>&rsquo; (Image, i.e. binary), or &lsquo;<tt>B</tt>&rsquo; (a synonym for &lsquo;<tt>I</tt>&rsquo;).
</p>
<p>The FTP default for a transfer is ASCII.  However, if <tt>zftp</tt> finds
that the remote host is a UNIX machine with 8-bit byes, it will
automatically switch to using binary for file transfers upon
<tt>open</tt>.  This can subsequently be overridden.
</p>
<p>The transfer type is only passed to the remote host when a data
connection is established; this command involves no network overhead.
</p>
</dd>
<dt><tt>ascii</tt></dt>
<dd><p>The same as <tt>type A</tt>.
</p>
</dd>
<dt><tt>binary</tt></dt>
<dd><p>The same as <tt>type I</tt>.
</p>
</dd>
<dt><tt>mode</tt> [ <tt>S</tt> | <tt>B</tt> ]</dt>
<dd><p>Set the mode type to stream (<tt>S</tt>) or block (<tt>B</tt>).  Stream mode is
the default; block mode is not widely supported.
</p>
</dd>
<dt><tt>remote</tt> <var>file</var> ...</dt>
<dt><tt>local</tt> [ <var>file</var> ... ]</dt>
<dd><p>Print the size and last modification time of the remote or local
files.  If there is more than one item on the list, the name of the
file is printed first.  The first number is the file size, the second
is the last modification time of the file in the format
<tt>CCYYMMDDhhmmSS</tt> consisting of year, month, date, hour, minutes and
seconds in GMT.  Note that this format, including the length, is
guaranteed, so that time strings can be directly compared via the
<tt>[[</tt> builtin&rsquo;s <tt>&lt;</tt> and <tt>&gt;</tt> operators, even if they are too long
to be represented as integers.
</p>
<p>Not all servers support the commands for retrieving this information.
In that case, the <tt>remote</tt> command will print nothing and return
status 2, compared with status 1 for a file not found.
</p>
<p>The <tt>local</tt> command (but not <tt>remote</tt>) may be used with no
arguments, in which case the information comes from examining file
descriptor zero.  This is the same file as seen by a <tt>put</tt> command
with no further redirection.
</p>
</dd>
<dt><tt>get</tt> <var>file</var> ...</dt>
<dd><p>Retrieve all <var>file</var>s from the server, concatenating them
and sending them to standard output.
</p>
</dd>
<dt><tt>put</tt> <var>file</var> ...</dt>
<dd><p>For each <var>file</var>, read a file from standard input and send that to
the remote host with the given name.
</p>
</dd>
<dt><tt>append</tt> <var>file</var> ...</dt>
<dd><p>As <tt>put</tt>, but if the remote <var>file</var> already exists, data is
appended to it instead of overwriting it.
</p>
</dd>
<dt><tt>getat</tt> <var>file</var> <var>point</var></dt>
<dt><tt>putat</tt> <var>file</var> <var>point</var></dt>
<dt><tt>appendat</tt> <var>file</var> <var>point</var></dt>
<dd><p>Versions of <tt>get</tt>, <tt>put</tt> and <tt>append</tt> which will start the
transfer at the given <var>point</var> in the remote <var>file</var>.  This is
useful for appending to an incomplete local file.  However, note that
this ability is not universally supported by servers (and is not quite
the behaviour specified by the standard).
</p>
</dd>
<dt><tt>delete</tt> <var>file</var> ...</dt>
<dd><p>Delete the list of files on the server.
</p>
</dd>
<dt><tt>mkdir</tt> <var>directory</var></dt>
<dd><p>Create a new directory <var>directory</var> on the server.
</p>
</dd>
<dt><tt>rmdir</tt> <var>directory</var></dt>
<dd><p>Delete the directory <var>directory</var>  on the server.
</p>
</dd>
<dt><tt>rename</tt> <var>old-name</var> <var>new-name</var></dt>
<dd><p>Rename file <var>old-name</var> to <var>new-name</var> on the server.
</p>
</dd>
<dt><tt>site</tt> <var>arg</var> ...</dt>
<dd><p>Send a host-specific command to the server.  You will probably
only need this if instructed by the server to use it.
</p>
</dd>
<dt><tt>quote</tt> <var>arg</var> ...</dt>
<dd><p>Send the raw FTP command sequence to the server.  You should be
familiar with the FTP command set as defined in RFC959 before doing
this.  Useful commands may include <tt>STAT</tt> and <tt>HELP</tt>.  Note also
the mechanism for returning messages as described for the variable
<tt>ZFTP_VERBOSE</tt> below, in particular that all messages from the
control connection are sent to standard error.
</p>
</dd>
<dt><tt>close</tt></dt>
<dt><tt>quit</tt></dt>
<dd><p>Close the current data connection.  This unsets the shell parameters
<tt>ZFTP_HOST</tt>, <tt>ZFTP_PORT</tt>, <tt>ZFTP_IP</tt>, <tt>ZFTP_SYSTEM</tt>, <tt>ZFTP_USER</tt>,
<tt>ZFTP_ACCOUNT</tt>, <tt>ZFTP_PWD</tt>, <tt>ZFTP_TYPE</tt> and <tt>ZFTP_MODE</tt>.
</p>
</dd>
<dt><tt>session</tt> [ <var>sessname</var> ]</dt>
<dd><p>Allows multiple FTP sessions to be used at once.  The name of the session
is an arbitrary string of characters; the default session is called
&lsquo;<tt>default</tt>&rsquo;.  If this command is called without an argument, it will list
all the current sessions; with an argument, it will either switch to the
existing session called <var>sessname</var>, or create a new session of that name.
</p>
<p>Each session remembers the status of the connection, the set of
connection-specific shell parameters (the same set as are unset when a
connection closes, as given in the description of <tt>close</tt>), and any user
parameters specified with the <tt>params</tt> subcommand.  Changing to a
previous session restores those values; changing to a new session
initialises them in the same way as if <tt>zftp</tt> had just been loaded.  The
name of the current session is given by the parameter <tt>ZFTP_SESSION</tt>.
</p>
</dd>
<dt><tt>rmsession</tt> [ <var>sessname</var> ]</dt>
<dd><p>Delete a session; if a name is not given, the current session is deleted.
If the current session is deleted, the earliest existing session becomes
the new current session, otherwise the current session is not changed.
If the session being deleted is the only one, a new session called
&lsquo;<tt>default</tt>&rsquo; is created and becomes the current session; note that this is
a new session even if the session being deleted is also called
&lsquo;<tt>default</tt>&rsquo;. It is recommended that sessions not be deleted while
background commands which use <tt>zftp</tt> are still active.
</p>
</dd>
</dl>


<hr>
<a name="Parameters-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Subcommands" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Functions-1" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.31.2 Parameters</h3>
<a name="index-zftp_002c-parameters"></a>
<p>The following shell parameters are used by <tt>zftp</tt>.  Currently none
of them are special.
</p>
<dl compact="compact">
<dd><a name="index-ZFTP_005fTMOUT"></a>
</dd>
<dt><tt>ZFTP_TMOUT</tt></dt>
<dd><p>Integer.  The time in seconds to wait for a network operation to
complete before returning an error.  If this is not set when the
module is loaded, it will be given the default value 60.  A value of
zero turns off timeouts.  If a timeout occurs on the control
connection it will be closed.  Use a larger value if this occurs too
frequently.
</p>
<a name="index-ZFTP_005fIP"></a>
</dd>
<dt><tt>ZFTP_IP</tt></dt>
<dd><p>Readonly.  The IP address of the current connection in dot notation.
</p>
<a name="index-ZFTP_005fHOST"></a>
</dd>
<dt><tt>ZFTP_HOST</tt></dt>
<dd><p>Readonly.  The hostname of the current remote server.  If the host was
opened as an IP number, <tt>ZFTP_HOST</tt> contains that instead; this
saves the overhead for a name lookup, as IP numbers are most commonly
used when a nameserver is unavailable.
</p>
<a name="index-ZFTP_005fPORT"></a>
</dd>
<dt><tt>ZFTP_PORT</tt></dt>
<dd><p>Readonly.  The number of the remote TCP port to which the connection is
open (even if the port was originally specified as a named service).
Usually this is the standard FTP port, 21.
</p>
<p>In the unlikely event that your system does not have the appropriate
conversion functions, this appears in network byte order.  If your
system is little-endian, the port then consists of two swapped bytes and the
standard port will be reported as 5376.  In that case, numeric ports passed
to <tt>zftp open</tt> will also need to be in this format.
</p>
<a name="index-ZFTP_005fSYSTEM"></a>
</dd>
<dt><tt>ZFTP_SYSTEM</tt></dt>
<dd><p>Readonly.  The system type string returned by the server in response
to an FTP <tt>SYST</tt> request.  The most interesting case is a string
beginning <tt>&quot;UNIX Type: L8&quot;</tt>, which ensures maximum compatibility
with a local UNIX host.
</p>
<a name="index-ZFTP_005fTYPE"></a>
</dd>
<dt><tt>ZFTP_TYPE</tt></dt>
<dd><p>Readonly.  The type to be used for data transfers , either &lsquo;<tt>A</tt>&rsquo; or
&lsquo;<tt>I</tt>&rsquo;.   Use the <tt>type</tt> subcommand to change this.
</p>
<a name="index-ZFTP_005fUSER"></a>
</dd>
<dt><tt>ZFTP_USER</tt></dt>
<dd><p>Readonly.  The username currently logged in, if any.
</p>
<a name="index-ZFTP_005fACCOUNT"></a>
</dd>
<dt><tt>ZFTP_ACCOUNT</tt></dt>
<dd><p>Readonly.  The account name of the current user, if any.  Most servers
do not require an account name.
</p>
<a name="index-ZFTP_005fPWD"></a>
</dd>
<dt><tt>ZFTP_PWD</tt></dt>
<dd><p>Readonly.  The current directory on the server.
</p>
<a name="index-ZFTP_005fCODE"></a>
</dd>
<dt><tt>ZFTP_CODE</tt></dt>
<dd><p>Readonly.  The three digit code of the last FTP reply from the server
as a string.  This can still be read after the connection is closed, and
is not changed when the current session changes.
</p>
<a name="index-ZFTP_005fREPLY"></a>
</dd>
<dt><tt>ZFTP_REPLY</tt></dt>
<dd><p>Readonly.  The last line of the last reply sent by the server.  This
can still be read after the connection is closed, and is not changed when
the current session changes.
</p>
<a name="index-ZFTP_005fSESSION"></a>
</dd>
<dt><tt>ZFTP_SESSION</tt></dt>
<dd><p>Readonly.  The name of the current FTP session; see the description of the
<tt>session</tt> subcommand.
</p>
<a name="index-ZFTP_005fPREFS"></a>
</dd>
<dt><tt>ZFTP_PREFS</tt></dt>
<dd><p>A string of preferences for altering aspects of <tt>zftp</tt>&rsquo;s behaviour.
Each preference is a single character.  The following are defined:
</p>
<dl compact="compact">
<dt><tt>P</tt></dt>
<dd><p>Passive:  attempt to make the remote server initiate data transfers.
This is slightly more efficient than sendport mode.  If the letter
<tt>S</tt> occurs later in the string, <tt>zftp</tt> will use sendport mode if
passive mode is not available.
</p>
</dd>
<dt><tt>S</tt></dt>
<dd><p>Sendport:  initiate transfers by the FTP <tt>PORT</tt> command.  If this
occurs before any <tt>P</tt> in the string, passive mode will never be
attempted.
</p>
</dd>
<dt><tt>D</tt></dt>
<dd><p>Dumb:  use only the bare minimum of FTP commands.  This prevents
the variables <tt>ZFTP_SYSTEM</tt> and <tt>ZFTP_PWD</tt> from being set, and
will mean all connections default to ASCII type.  It may prevent
<tt>ZFTP_SIZE</tt> from being set during a transfer if the server
does not send it anyway (many servers do).
</p>
</dd>
</dl>

<p>If <tt>ZFTP_PREFS</tt> is not set when <tt>zftp</tt> is loaded, it will be set to a
default of &lsquo;<tt>PS</tt>&rsquo;, i.e. use passive mode if available, otherwise
fall back to sendport mode.
</p>
<a name="index-ZFTP_005fVERBOSE"></a>
</dd>
<dt><tt>ZFTP_VERBOSE</tt></dt>
<dd><p>A string of digits between 0 and 5 inclusive, specifying which
responses from the server should be printed.  All responses go to
standard error.  If any of the numbers 1 to 5 appear in the string,
raw responses from the server with reply codes beginning with that
digit will be printed to standard error.  The first digit of the three
digit reply code is defined by RFC959 to correspond to:
</p>
<dl compact="compact">
<dt>1.</dt>
<dd><p>A positive preliminary reply.
</p>
</dd>
<dt>2.</dt>
<dd><p>A positive completion reply.
</p>
</dd>
<dt>3.</dt>
<dd><p>A positive intermediate reply.
</p>
</dd>
<dt>4.</dt>
<dd><p>A transient negative completion reply.
</p>
</dd>
<dt>5.</dt>
<dd><p>A permanent negative completion reply.
</p>
</dd>
</dl>

<p>It should be noted that, for unknown reasons, the reply &lsquo;Service not
available&rsquo;, which forces termination of a connection, is classified as
421, i.e. &lsquo;transient negative&rsquo;, an interesting interpretation of the word
&lsquo;transient&rsquo;.
</p>
<p>The code 0 is special:  it indicates that all but the last line of
multiline replies read from the server will be printed to standard
error in a processed format.  By convention, servers use this
mechanism for sending information for the user to read.  The
appropriate reply code, if it matches the same response, takes
priority.
</p>
<p>If <tt>ZFTP_VERBOSE</tt> is not set when <tt>zftp</tt> is loaded, it will be
set to the default value <tt>450</tt>, i.e., messages destined for the user
and all errors will be printed.  A null string is valid and
specifies that no messages should be printed.
</p>
</dd>
</dl>


<hr>
<a name="Functions-1"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Parameters-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#Problems" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.31.3 Functions</h3>
<a name="index-zftp_002c-functions"></a>

<dl compact="compact">
<dd><a name="index-zftp_005fchpwd_002c-specification"></a>
</dd>
<dt><tt>zftp_chpwd</tt></dt>
<dd><p>If this function is set by the user, it is called every time the
directory changes on the server, including when a user is logged
in, or when a connection is closed.  In the last case, <tt>$ZFTP_PWD</tt>
will be unset; otherwise it will reflect the new directory.
</p>
<a name="index-zftp_005fprogress_002c-specification"></a>
</dd>
<dt><tt>zftp_progress</tt></dt>
<dd><p>If this function is set by the user, it will be called during
a <tt>get</tt>, <tt>put</tt> or <tt>append</tt> operation each time sufficient data
has been received from the host.  During a <tt>get</tt>, the data is sent
to standard output, so it is vital that this function should write
to standard error or directly to the terminal, <em>not</em> to standard
output.
</p>
<p>When it is called with a transfer in progress, the following
additional shell parameters are set:
</p>
<dl compact="compact">
<dd><a name="index-ZFTP_005fFILE"></a>
</dd>
<dt><tt>ZFTP_FILE</tt></dt>
<dd><p>The name of the remote file being transferred from or to.
</p>
<a name="index-ZFTP_005fTRANSFER"></a>
</dd>
<dt><tt>ZFTP_TRANSFER</tt></dt>
<dd><p>A <tt>G</tt> for a <tt>get</tt> operation and a <tt>P</tt> for a <tt>put</tt> operation.
</p>
<a name="index-ZFTP_005fSIZE"></a>
</dd>
<dt><tt>ZFTP_SIZE</tt></dt>
<dd><p>The total size of the complete file being transferred:
the same as the first value provided by the
<tt>remote</tt> and <tt>local</tt> subcommands for a particular file.
If the server cannot supply this value for a remote file being
retrieved, it will not be set.  If input is from a pipe the value may
be incorrect and correspond simply to a full pipe buffer.
</p>
<a name="index-ZFTP_005fCOUNT"></a>
</dd>
<dt><tt>ZFTP_COUNT</tt></dt>
<dd><p>The amount of data so far transferred; a number between zero and
<tt>$ZFTP_SIZE</tt>, if that is set.  This number is always available.
</p>
</dd>
</dl>

<p>The function is initially called with <tt>ZFTP_TRANSFER</tt> set
appropriately and <tt>ZFTP_COUNT</tt> set to zero.  After the transfer is
finished, the function will be called one more time with
<tt>ZFTP_TRANSFER</tt> set to <tt>GF</tt> or <tt>PF</tt>, in case it wishes to tidy
up.  It is otherwise never called twice with the same value of
<tt>ZFTP_COUNT</tt>.
</p>
<p>Sometimes the progress meter may cause disruption.  It is up to the
user to decide whether the function should be defined and to use
<tt>unfunction</tt> when necessary.
</p>
</dd>
</dl>


<hr>
<a name="Problems"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Functions-1" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzftp-Module" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzle-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<h3 class="subsection">22.31.4 Problems</h3>
<a name="index-zftp_002c-problems"></a>

<p>A connection may not be opened in the left hand side of a pipe as this
occurs in a subshell and the file information is not updated in the main
shell.  In the case of type or mode changes or closing the connection in a
subshell, the information is returned but variables are not updated until
the next call to <tt>zftp</tt>.  Other status changes in subshells will not be
reflected by changes to the variables (but should be otherwise harmless).
</p>
<p>Deleting sessions while a <tt>zftp</tt> command is active in the background can
have unexpected effects, even if it does not use the session being deleted.
This is because all shell subprocesses share information on the state of
all connections, and deleting a session changes the ordering of that
information.
</p>
<p>On some operating systems, the control connection is not valid after a
fork(), so that operations in subshells, on the left hand side
of a pipeline, or in the background are not possible, as they should be.
This is presumably a bug in the operating system.
</p><hr>
<a name="The-zsh_002fzle-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Problems" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzleparameter-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzle-Module-1"></a>
<h2 class="section">22.32 The zsh/zle Module</h2>

<p>The <tt>zsh/zle</tt> module contains the Zsh Line Editor.  See
<a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>.
</p><hr>
<a name="The-zsh_002fzleparameter-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzle-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzprof-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzleparameter-Module-1"></a>
<h2 class="section">22.33 The zsh/zleparameter Module</h2>

<a name="index-parameters_002c-special-2"></a>
<p>The <tt>zsh/zleparameter</tt> module defines two special parameters that can be 
used to access internal information of the Zsh Line Editor (see
<a href="Zsh-Line-Editor.html#Zsh-Line-Editor">Zsh Line Editor</a>).
</p>
<dl compact="compact">
<dd><a name="index-keymaps-2"></a>
</dd>
<dt><tt>keymaps</tt></dt>
<dd><p>This array contains the names of the keymaps currently defined.
</p>
<a name="index-widgets-1"></a>
</dd>
<dt><tt>widgets</tt></dt>
<dd><p>This associative array contains one entry per widget. The name 
of the widget is the key and the value gives information about the
widget. It is either
  the string &lsquo;<tt>builtin</tt>&rsquo; for builtin widgets,
  a string of the form &lsquo;<tt>user:</tt><var>name</var>&rsquo; for user-defined widgets,
    where <var>name</var> is the name of the shell function implementing the widget,
  a string of the form &lsquo;<tt>completion:</tt><var>type</var><tt>:</tt><var>name</var>&rsquo;
    for completion widgets,
  or a null value if the widget is not yet fully defined.
In the penultimate case, <var>type</var> is the name of the builtin widget the
completion widget imitates in its behavior and <var>name</var> is the name
of the shell function implementing the completion widget.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fzprof-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzleparameter-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzpty-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzprof-Module-1"></a>
<h2 class="section">22.34 The zsh/zprof Module</h2>

<a name="index-functions_002c-profiling"></a>
<p>When loaded, the <tt>zsh/zprof</tt> causes shell functions to be profiled.
The profiling results can be obtained with the <tt>zprof</tt>
builtin command made available by this module.  There is no way to turn 
profiling off other than unloading the module.
</p>
<dl compact="compact">
<dd><a name="index-zprof"></a>
</dd>
<dt><tt>zprof</tt> [ <tt>-c</tt> ]</dt>
<dd><p>Without the <tt>-c</tt> option, <tt>zprof</tt> lists profiling results to
standard output.  The format is comparable to that of commands like
<tt>gprof</tt>.
</p>
<p>At the top there is a summary listing all functions that were called
at least once.  This summary is sorted in decreasing order of the
amount of time spent in each.  The lines contain
the number of the function in order, which is used in 
other parts of the list in suffixes of the form
&lsquo;<tt>[</tt><var>num</var><tt>]</tt>&rsquo;, then the number of calls made to the function.
The next three columns list the time in
milliseconds spent in the function and its descendants, the average
time in milliseconds spent in the function and its descendants per
call and the percentage of time spent in all shell functions used in
this function and its descendants.  The following three columns give
the same information, but counting only the time spent in the function 
itself.  The final column shows the name of the function.
</p>
<p>After the summary, detailed information about every function that was
invoked is listed, sorted in decreasing order of the amount of time spent
in each function and its descendants.  Each of these entries consists of
descriptions for the functions that called the function described, the
function itself, and the functions that were called from it.  The
description for the function itself has the same format as in the summary
(and shows the same information).  The other lines don&rsquo;t show the number of
the function at the beginning and have their function named indented to
make it easier to distinguish the line showing the function described in
the section from the surrounding lines.
</p>
<p>The information shown in this case is almost the same as in the summary,
but only refers to the call hierarchy being displayed.  For example, for a
calling function the column showing the total running time lists the time
spent in the described function and its descendants only for the times when
it was called from that particular calling function.  Likewise, for a
called function, this columns lists the total time spent in the called
function and its descendants only for the times when it was called from the
function described.
</p>
<p>Also in this case, the column showing the number of calls to a function
also shows a slash and then the total number of invocations made to the
called function.
</p>
<p>As long as the <tt>zsh/zprof</tt> module is loaded, profiling will be done and
multiple invocations of the <tt>zprof</tt> builtin command will show the
times and numbers of calls since the module was loaded.  With the
<tt>-c</tt> option, the <tt>zprof</tt> builtin command will reset its internal
counters and will not show the listing.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fzpty-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzprof-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzselect-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzpty-Module-1"></a>
<h2 class="section">22.35 The zsh/zpty Module</h2>

<p>The <tt>zsh/zpty</tt> module offers one builtin:
</p>
<dl compact="compact">
<dd><a name="index-zpty"></a>
</dd>
<dt><tt>zpty</tt> [ <tt>-e</tt> ] [ <tt>-b</tt> ] <var>name</var> [ <var>arg</var> ... ]</dt>
<dd><p>The arguments following <var>name</var> are concatenated with spaces between,
then executed as a command, as if passed to the <tt>eval</tt> builtin.  The
command runs under a newly assigned pseudo-terminal; this is useful for
running commands non-interactively which expect an interactive
environment.  The <var>name</var> is not part of the command, but is used to
refer to this command in later calls to <tt>zpty</tt>.
</p>
<p>With the <tt>-e</tt> option, the pseudo-terminal is set up so that input
characters are echoed.
</p>
<p>With the <tt>-b</tt> option, input to and output from the pseudo-terminal are
made non-blocking.
</p>
<p>The shell parameter <tt>REPLY</tt> is set to the file descriptor assigned to
the master side of the pseudo-terminal.  This allows the terminal to be
monitored with ZLE descriptor handlers (see <a href="Zsh-Line-Editor.html#Zle-Builtins">Zle Builtins</a>) or manipulated with <tt>sysread</tt> and
<tt>syswrite</tt> (see <a href="#The-zsh_002fsystem-Module">The zsh/system Module</a>).  <em>Warning</em>: Use of <tt>sysread</tt>
and <tt>syswrite</tt> is <em>not</em> recommended, use <tt>zpty -r</tt> and <tt>zpty -w</tt>
unless you know exactly what you are doing.
</p>
</dd>
<dt><tt>zpty</tt> <tt>-d</tt> [ <var>name</var> ... ]</dt>
<dd><p>The second form, with the <tt>-d</tt> option, is used to delete commands
previously started, by supplying a list of their <var>name</var>s.  If no
<var>name</var> is given, all commands are deleted.  Deleting a command causes
the HUP signal to be sent to the corresponding process.
</p>
</dd>
<dt><tt>zpty</tt> <tt>-w</tt> [ <tt>-n</tt> ] <var>name</var> [ <var>string</var> ... ]</dt>
<dd><p>The <tt>-w</tt> option can be used to send the to command <var>name</var> the given
<var>string</var>s as input (separated by spaces).  If the <tt>-n</tt> option is
<em>not</em> given, a newline is added at the end.
</p>
<p>If no <var>string</var> is provided, the standard input is copied to the
pseudo-terminal; this may stop before copying the full input if the
pseudo-terminal is non-blocking.  The exact input is always copied:
the <tt>-n</tt> option is not applied.
</p>
<p>Note that the command under the pseudo-terminal sees this input as if it
were typed, so beware when sending special tty driver characters such as
word-erase, line-kill, and end-of-file.
</p>
</dd>
<dt><tt>zpty</tt> <tt>-r</tt> [ <tt>-mt</tt> ] <var>name</var> [ <var>param</var> [ <var>pattern</var> ] ]</dt>
<dd><p>The <tt>-r</tt> option can be used to read the output of the command <var>name</var>.
With only a <var>name</var> argument, the output read is copied to the standard
output.  Unless the pseudo-terminal is non-blocking, copying continues
until the command under the pseudo-terminal exits; when non-blocking, only
as much output as is immediately available is copied.  The return status is
zero if any output is copied.
</p>
<p>When also given a <var>param</var> argument, at most one line is read and stored
in the parameter named <var>param</var>.  Less than a full line may be read if
the pseudo-terminal is non-blocking.  The return status is zero if at least
one character is stored in <var>param</var>.
</p>
<p>If a <var>pattern</var> is given as well, output is read until the whole string
read matches the <var>pattern</var>, even in the non-blocking case.  The return
status is zero if the string read matches the pattern, or if the command
has exited but at least one character could still be read.  If the option
<tt>-m</tt> is present, the return status is zero only if the pattern matches.
As of this writing, a maximum of one megabyte of output can be consumed
this way; if a full megabyte is read without matching the pattern, the
return status is non-zero.
</p>
<p>In all cases, the return status is non-zero if nothing could be read, and
is <tt>2</tt> if this is because the command has finished.
</p>
<p>If the <tt>-r</tt> option is combined with the <tt>-t</tt> option, <tt>zpty</tt> tests
whether output is available before trying to read.  If no output is
available, <tt>zpty</tt> immediately returns the status <tt>1</tt>.  When used
with a <var>pattern</var>, the behaviour on a failed poll is similar to
when the command has exited:  the return value is zero if at least
one character could still be read even if the pattern failed to match.
</p>
</dd>
<dt><tt>zpty</tt> <tt>-t</tt> <var>name</var></dt>
<dd><p>The <tt>-t</tt> option without the <tt>-r</tt> option can be used to test
whether the command <var>name</var> is still running.  It returns a zero
status if the command is running and a non-zero value otherwise.
</p>
</dd>
<dt><tt>zpty</tt> [ <tt>-L</tt> ]</dt>
<dd><p>The last form, without any arguments, is used to list the commands
currently defined.  If the <tt>-L</tt> option is given, this is done in the
form of calls to the <tt>zpty</tt> builtin.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fzselect-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzpty-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzutil-Module" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzselect-Module-1"></a>
<h2 class="section">22.36 The zsh/zselect Module</h2>

<p>The <tt>zsh/zselect</tt> module makes available one builtin command:
</p>
<dl compact="compact">
<dd><a name="index-zselect"></a>
<a name="index-select_002c-system-call"></a>
<a name="index-file-descriptors_002c-waiting-for"></a>
</dd>
<dt><tt>zselect</tt> [ <tt>-rwe</tt> ] [ <tt>-t</tt> <var>timeout</var> ] [ <tt>-a</tt> <var>array</var> ] [ <tt>-A</tt> <var>assoc</var> ] [ <var>fd</var> ... ]</dt>
<dd><p>The <tt>zselect</tt> builtin is a front-end to the &lsquo;select&rsquo; system call, which
blocks until a file descriptor is ready for reading or writing, or has an
error condition, with an optional timeout.  If this is not available on
your system, the command prints an error message and returns status 2
(normal errors return status 1).  For more information, see your systems
documentation for man page select(3).  Note there is no connection with the
shell builtin of the same name.
</p>
<p>Arguments and options may be intermingled in any order.  Non-option
arguments are file descriptors, which must be decimal integers.  By
default, file descriptors are to be tested for reading, i.e. <tt>zselect</tt>
will return when data is available to be read from the file descriptor, or
more precisely, when a read operation from the file descriptor will not
block.  After a <tt>-r</tt>, <tt>-w</tt> and <tt>-e</tt>, the given file descriptors are
to be tested for reading, writing, or error conditions.  These options and
an arbitrary list of file descriptors may be given in any order.
</p>
<p>(The presence of an &lsquo;error condition&rsquo; is not well defined in the
documentation for many implementations of the select system call.
According to recent versions of the POSIX specification, it is really an
<em>exception</em> condition, of which the only standard example is out-of-band
data received on a socket.  So zsh users are unlikely to find the <tt>-e</tt>
option useful.)
</p>
<p>The option &lsquo;<tt>-t</tt> <var>timeout</var>&rsquo; specifies a timeout in hundredths of a
second.  This may be zero, in which case the file descriptors will simply
be polled and <tt>zselect</tt> will return immediately.  It is possible to call
zselect with no file descriptors and a non-zero timeout for use as a
finer-grained replacement for &lsquo;sleep&rsquo;; note, however, the return status is
always 1 for a timeout.
</p>
<p>The option &lsquo;<tt>-a</tt> <var>array</var>&rsquo; indicates that <var>array</var> should be set to
indicate the file descriptor(s) which are ready.  If the option
is not
given, the array <tt>reply</tt> will be used for this purpose.  The array will
contain a string similar to the arguments for <tt>zselect</tt>.  For example,
</p>
<div class="example">
<pre class="example">zselect -t 0 -r 0 -w 1
</pre></div>

<p>might return immediately with status 0 and <tt>$reply</tt> containing &lsquo;<tt>-r 0 -w
1</tt>&rsquo; to show that both file descriptors are ready for the requested
operations.
</p>
<p>The option &lsquo;<tt>-A</tt> <var>assoc</var>&rsquo; indicates that the associative array
<var>assoc</var> should be set to indicate the file descriptor(s)
which are ready.  This option overrides the option <tt>-a</tt>, nor will
<tt>reply</tt> be modified.  The keys of <tt>assoc</tt> are the file descriptors, and
the corresponding values are any of the characters &lsquo;<tt>rwe</tt>&rsquo; to indicate
the condition.
</p>
<p>The command returns status 0 if some file descriptors are ready for
reading.  If the operation timed out, or a timeout of 0 was given and no
file descriptors were ready, or there was an error, it returns status 1 and
the array will not be set (nor modified in any way).  If there was an error
in the select operation the appropriate error message is printed.
</p>
</dd>
</dl>
<hr>
<a name="The-zsh_002fzutil-Module"></a>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="#The-zsh_002fzselect-Module" title="Previous section in reading order"> &lt; </a>]</td>
<td valign="middle" align="left">[<a href="#Zsh-Modules" title="Up section"> Up </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next section in reading order"> &gt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>

<a name="The-zsh_002fzutil-Module-1"></a>
<h2 class="section">22.37 The zsh/zutil Module</h2>

<a name="index-builtins_002c-utility"></a>
<p>The <tt>zsh/zutil</tt> module only adds some builtins:
</p>
<dl compact="compact">
<dd><a name="index-zstyle"></a>
</dd>
<dt><tt>zstyle</tt> [ <tt>-L</tt> [ <var>pattern</var> [ <var>style</var> ] ] ]</dt>
<dt><tt>zstyle</tt> [ <tt>-e</tt> | <tt>-</tt> | <tt>-</tt><tt>-</tt> ] <var>pattern</var> <var>style</var> <var>string</var> ...</dt>
<dt><tt>zstyle -d</tt> [ <var>pattern</var> [ <var>style</var> ... ] ]</dt>
<dt><tt>zstyle -g</tt> <var>name</var> [ <var>pattern</var> [ <var>style</var> ] ]</dt>
<dt><tt>zstyle -</tt>{<tt>a</tt>|<tt>b</tt>|<tt>s</tt>} <var>context</var> <var>style</var> <var>name</var> [ <var>sep</var> ]</dt>
<dt><tt>zstyle -</tt>{<tt>T</tt>|<tt>t</tt>} <var>context</var> <var>style</var> [ <var>string</var> ... ]</dt>
<dt><tt>zstyle -m</tt> <var>context</var> <var>style</var> <var>pattern</var></dt>
<dd><p>This builtin command is used to define and lookup styles.  Styles are
pairs of names and values, where the values consist of any number of
strings.  They are stored together with patterns and lookup is done by
giving a string, called the &lsquo;context&rsquo;, which is compared to the
patterns.  The definition stored for the first matching pattern will be 
returned.
</p>
<p>For ordering of comparisons, patterns are searched from most specific to
least specific, and patterns that are equally specific keep the order in 
which they were defined.  A pattern is considered to be more specific
than another if it contains more components (substrings separated by
colons) or if the patterns for the components are more specific, where 
simple strings are considered to be more specific than patterns and
complex patterns are considered to be more specific than the pattern
&lsquo;<tt>*</tt>&rsquo;.
</p>
<p>The first form (without arguments) lists the definitions.  Styles
are shown in alphabetic order and patterns are shown in the order
<tt>zstyle</tt> will test them.
</p>
<p>If the <tt>-L</tt> option is given, listing is done in the form of calls to
<tt>zstyle</tt>.  The optional first argument is a pattern which will be matched
against the string supplied as the pattern for the context; note that
this means, for example, &lsquo;<tt>zstyle -L &quot;:completion:*&quot;</tt>&rsquo; will
match any supplied pattern beginning &lsquo;<tt>:completion:</tt>&rsquo;, not
just <tt>&quot;:completion:*&quot;</tt>:  use <tt>&quot;:completion:\*&quot;</tt> to match that.
The optional second argument limits the output to a specific <var>style</var> (not a
pattern).  <tt>-L</tt> is not compatible with any other options.
</p>
<p>The other forms are the following:
</p>
<dl compact="compact">
<dt><tt>zstyle</tt> [ <tt>-</tt> | <tt>-</tt><tt>-</tt> | <tt>-e</tt> ] <var>pattern</var> <var>style</var> <var>string</var> ...</dt>
<dd><a name="index-reply_002c-use-of-4"></a>
<p>Defines the given <var>style</var> for the <var>pattern</var> with the <var>string</var>s as
the value.  If the <tt>-e</tt> option is given, the <var>string</var>s will be
concatenated (separated by spaces) and the resulting string will be
evaluated (in the same way as it is done by the <tt>eval</tt> builtin
command) when the style is looked up.  In this case the parameter
&lsquo;<tt>reply</tt>&rsquo; must be assigned to set the strings returned after the
evaluation.  Before evaluating the value, <tt>reply</tt> is unset, and
if it is still unset after the evaluation, the style is treated as if
it were not set.
</p>
</dd>
<dt><tt>zstyle -d</tt> [ <var>pattern</var> [ <var>style</var> ... ] ]</dt>
<dd><p>Delete style definitions. Without arguments all definitions are deleted,
with a <var>pattern</var> all definitions for that pattern are deleted and if
any <var>style</var>s are given, then only those styles are deleted for the
<var>pattern</var>.
</p>
</dd>
<dt><tt>zstyle -g</tt> <var>name</var> [ <var>pattern</var> [ <var>style</var> ] ]</dt>
<dd><p>Retrieve a style definition. The <var>name</var> is
used as the name of an array in which the results are stored. Without
any further arguments, all patterns defined are returned. With a
<var>pattern</var> the styles defined for that pattern are returned and with 
both a <var>pattern</var> and a <var>style</var>, the value strings of that
combination is returned.
</p>
</dd>
</dl>

<p>The other forms can be used to look up or test patterns.
</p>
<dl compact="compact">
<dt><tt>zstyle -s</tt> <var>context</var> <var>style</var> <var>name</var> [ <var>sep</var> ]</dt>
<dd><p>The parameter <var>name</var> is set to the value of the style interpreted as a
string.  If the value contains several strings they are concatenated with
spaces (or with the <var>sep</var> string if that is given) between them.
</p>
</dd>
<dt><tt>zstyle -b</tt> <var>context</var> <var>style</var> <var>name</var></dt>
<dd><p>The value is stored in <var>name</var> as a boolean, i.e. as the string
&lsquo;<tt>yes</tt>&rsquo; if the value has only one string and that string is equal to one
of &lsquo;<tt>yes</tt>&rsquo;, &lsquo;<tt>true</tt>&rsquo;, &lsquo;<tt>on</tt>&rsquo;, or &lsquo;<tt>1</tt>&rsquo;. If the value is any other
string or has more than one string, the parameter is set to &lsquo;<tt>no</tt>&rsquo;.
</p>
</dd>
<dt><tt>zstyle -a</tt> <var>context</var> <var>style</var> <var>name</var></dt>
<dd><p>The value is stored in <var>name</var> as an array. If <var>name</var> is declared 
as an associative array,  the first, third, etc. strings are used as the
keys and the other strings are used as the values.
</p>
</dd>
<dt><tt>zstyle -t</tt> <var>context</var> <var>style</var> [ <var>string</var> ... ]</dt>
<dt><tt>zstyle -T</tt> <var>context</var> <var>style</var> [ <var>string</var> ... ]</dt>
<dd><p>Test the value of a style, i.e. the <tt>-t</tt> option only returns a status
(sets <tt>$?</tt>).  Without any <var>string</var> the return status is zero if the
style is defined for at least one matching pattern, has only one string in
its value, and that is equal to one of &lsquo;<tt>true</tt>&rsquo;, &lsquo;<tt>yes</tt>&rsquo;, &lsquo;<tt>on</tt>&rsquo; or
&lsquo;<tt>1</tt>&rsquo;. If any <var>string</var>s are given the status is zero if and only if
at least one of the <var>string</var>s is equal to at least one of the strings
in the value. If the style is defined but doesn&rsquo;t match, the return status
is <tt>1</tt>. If the style is not defined, the status is <tt>2</tt>.
</p>
<p>The <tt>-T</tt> option tests the values of the style like <tt>-t</tt>, but it
returns status zero (rather than <tt>2</tt>) if the style is not defined for any
matching pattern.
</p>
</dd>
<dt><tt>zstyle -m</tt> <var>context</var> <var>style</var> <var>pattern</var></dt>
<dd><p>Match a value. Returns status zero if the 
<var>pattern</var> matches at least one of the strings in the value.
</p>
</dd>
</dl>

<a name="index-zformat"></a>
</dd>
<dt><tt>zformat -f</tt> <var>param</var> <var>format</var> <var>spec</var> ...</dt>
<dt><tt>zformat -a</tt> <var>array</var> <var>sep</var> <var>spec</var> ...</dt>
<dd><p>This builtin provides two different forms of formatting. The first form 
is selected with the <tt>-f</tt> option. In this case the <var>format</var>
string will be modified by replacing sequences starting with a percent 
sign in it with strings from the <var>spec</var>s.  Each <var>spec</var> should be
of the form &lsquo;<var>char</var><tt>:</tt><var>string</var>&rsquo; which will cause every
appearance of the sequence &lsquo;<tt>%</tt><var>char</var>&rsquo; in <var>format</var> to be replaced 
by the <var>string</var>.  The &lsquo;<tt>%</tt>&rsquo; sequence may also contain optional
minimum and maximum field width specifications between the &lsquo;<tt>%</tt>&rsquo; and 
the &lsquo;<var>char</var>&rsquo; in the form &lsquo;<tt>%</tt><var>min</var><tt>.</tt><var>max</var><tt>c</tt>&rsquo;,
i.e. the minimum field width is given first and if the maximum field
width is used, it has to be preceded by a dot.  Specifying a minimum field
width makes the result be padded with spaces to the right if the
<var>string</var> is shorter than the requested width.  Padding to the left
can be achieved by giving a negative minimum field width.  If a maximum 
field width is specified, the <var>string</var> will be truncated after that
many characters.  After all &lsquo;<tt>%</tt>&rsquo; sequences for the given <var>spec</var>s
have been processed, the resulting string is stored in the parameter
<var>param</var>.
</p>
<p>The <tt>%</tt>-escapes also understand ternary expressions in the form used by
prompts.  The <tt>%</tt> is followed by a &lsquo;<tt>(</tt>&rsquo; and then an ordinary
format specifier character as described above.  There may be a set of
digits either before or after the &lsquo;<tt>(</tt>&rsquo;; these specify a test
number, which defaults to zero.  Negative numbers are also allowed.  An
arbitrary delimiter character follows the format specifier, which is
followed by a piece of &lsquo;true&rsquo; text, the delimiter character again, a piece
of &lsquo;false&rsquo; text, and a closing parenthesis.  The complete expression
(without the digits) thus looks like
&lsquo;<tt>%(</tt><var>X</var><tt>.</tt><var>text1</var><tt>.</tt><var>text2</var><tt>)</tt>&rsquo;, except that
the &lsquo;<tt>.</tt>&rsquo; character is arbitrary.  The value given for the format
specifier in the <var>char</var><tt>:</tt><var>string</var> expressions is evaluated as a
mathematical expression, and compared with the test number.  If they are
the same, <var>text1</var> is output, else <var>text2</var> is output.  A parenthesis
may be escaped in <var>text2</var> as <tt>%)</tt>.  Either of <var>text1</var> or
<var>text2</var> may contain nested <tt>%</tt>-escapes.
</p>
<p>For example:
</p>
<div class="example">
<pre class="example">zformat -f REPLY &quot;The answer is '%3(c.yes.no)'.&quot; c:3
</pre></div>

<p>outputs &quot;The answer is &rsquo;yes&rsquo;.&quot; to <tt>REPLY</tt> since the value for the format
specifier <tt>c</tt> is 3, agreeing with the digit argument to the ternary
expression.
</p>
<p>The second form, using the <tt>-a</tt> option, can be used for aligning
strings.  Here, the <var>spec</var>s are of the form
&lsquo;<var>left</var><tt>:</tt><var>right</var>&rsquo; where &lsquo;<var>left</var>&rsquo; and &lsquo;<var>right</var>&rsquo; are
arbitrary strings.  These strings are modified by replacing the colons
by the <var>sep</var> string and padding the <var>left</var> strings with spaces 
to the right so that the <var>sep</var> strings in the result (and hence the 
<var>right</var> strings after them) are all aligned if the strings are
printed below each other.  All strings without a colon are left
unchanged and all strings with an empty <var>right</var> string have the
trailing colon removed.  In both cases the lengths of the strings
are not used to determine how the other strings are to be aligned.
A colon in the <var>left</var> string can be escaped with a backslash.
The resulting strings are stored in the <var>array</var>.
</p>
<a name="index-zregexparse"></a>
</dd>
<dt><tt>zregexparse</tt></dt>
<dd><p>This implements some internals of the <tt>_regex_arguments</tt> function.
</p>
<a name="index-zparseopts"></a>
</dd>
<dt><tt>zparseopts</tt> [ <tt>-D</tt> <tt>-K</tt> <tt>-M</tt> <tt>-E</tt> ] [ <tt>-a</tt> <var>array</var> ] [ <tt>-A</tt> <var>assoc</var> ] [ <tt>-</tt> ] <var>spec</var> ...</dt>
<dd><p>This builtin simplifies the parsing of options in positional parameters,
i.e. the set of arguments given by <tt>$*</tt>.  Each <var>spec</var> describes one
option and must be of the form &lsquo;<var>opt</var>[<tt>=</tt><var>array</var>]&rsquo;.  If an option
described by <var>opt</var> is found in the positional parameters it is copied
into the <var>array</var> specified with the <tt>-a</tt> option; if the optional
&lsquo;<tt>=</tt><var>array</var>&rsquo; is given, it is instead copied into that array, which
should be declared as a normal array and never as an associative array.
</p>
<p>Note that it is an error to give any <var>spec</var> without an
&lsquo;<tt>=</tt><var>array</var>&rsquo; unless one of the <tt>-a</tt> or <tt>-A</tt> options is used.
</p>
<p>Unless the <tt>-E</tt> option is given, parsing stops at the first string
that isn&rsquo;t described by one of the <var>spec</var>s.  Even with <tt>-E</tt>,
parsing always stops at a positional parameter equal to &lsquo;<tt>-</tt>&rsquo; or
&lsquo;<tt>-</tt><tt>-</tt>&rsquo;.
</p>
<p>The <var>opt</var> description must be one of the following.  Any of the special
characters can appear in the option name provided it is preceded by a
backslash.
</p>
<dl compact="compact">
<dt><var>name</var></dt>
<dt><var>name</var><tt>+</tt></dt>
<dd><p>The <var>name</var> is the name of the option without the leading &lsquo;<tt>-</tt>&rsquo;.  To
specify a GNU-style long option, one of the usual two leading &lsquo;<tt>-</tt>&rsquo; must
be included in <var>name</var>; for example, a &lsquo;<tt>-</tt><tt>-file</tt>&rsquo; option is
represented by a <var>name</var> of &lsquo;<tt>-file</tt>&rsquo;.
</p>
<p>If a &lsquo;<tt>+</tt>&rsquo; appears after <var>name</var>, the option is appended to <var>array</var>
each time it is found in the positional parameters; without the &lsquo;<tt>+</tt>&rsquo;
only the <em>last</em> occurrence of the option is preserved.
</p>
<p>If one of these forms is used, the option takes no argument, so parsing
stops if the next positional parameter does not also begin with &lsquo;<tt>-</tt>&rsquo;
(unless the <tt>-E</tt> option is used).
</p>
</dd>
<dt><var>name</var><tt>:</tt></dt>
<dt><var>name</var><tt>:-</tt></dt>
<dt><var>name</var><tt>::</tt></dt>
<dd><p>If one or two colons are given, the option takes an argument; with one
colon, the argument is mandatory and with two colons it is optional.  The
argument is appended to the <var>array</var> after the option itself.
</p>
<p>An optional argument is put into the same array element as the option name
(note that this makes empty strings as arguments indistinguishable).  A
mandatory argument is added as a separate element unless the &lsquo;<tt>:-</tt>&rsquo; form
is used, in which case the argument is put into the same element.
</p>
<p>A &lsquo;<tt>+</tt>&rsquo; as described above may appear between the <var>name</var> and the
first colon.
</p>
</dd>
</dl>

<p>The options of <tt>zparseopts</tt> itself cannot be stacked because, for
example, the stack &lsquo;<tt>-DEK</tt>&rsquo; is indistinguishable from a <var>spec</var> for
the GNU-style long option &lsquo;<tt>&ndash;DEK</tt>&rsquo;.  The options of <tt>zparseopts</tt>
itself are:
</p>
<dl compact="compact">
<dt><tt>-a</tt> <var>array</var></dt>
<dd><p>As described above, this names the default array in which to store the
recognised options.
</p>
</dd>
<dt><tt>-A</tt> <var>assoc</var></dt>
<dd><p>If this is given, the options and their values are also put into an
associative array with the option names as keys and the arguments (if any)
as the values.
</p>
</dd>
<dt><tt>-D</tt></dt>
<dd><p>If this option is given, all options found are removed from the positional
parameters of the calling shell or shell function, up to but not including
any not described by the <var>spec</var>s.  This is similar to using the <tt>shift</tt>
builtin.
</p>
</dd>
<dt><tt>-K</tt></dt>
<dd><p>With this option, the arrays specified with the <tt>-a</tt> option and with the
&lsquo;<tt>=</tt><var>array</var>&rsquo; forms are kept unchanged when none of the <var>spec</var>s for
them is used.  Otherwise the entire array is replaced when any of the
<var>spec</var>s is used.  Individual elements of associative arrays specified
with the <tt>-A</tt> option are preserved by <tt>-K</tt>.  This allows assignment of
default values to arrays before calling <tt>zparseopts</tt>.
</p>
</dd>
<dt><tt>-M</tt></dt>
<dd><p>This changes the assignment rules to implement a map among equivalent
option names.  If any <var>spec</var> uses the &lsquo;<tt>=</tt><var>array</var>&rsquo; form, the
string <var>array</var> is interpreted as the name of another <var>spec</var>,
which is used to choose where to store the values.  If no other <var>spec</var>
is found, the values are stored as usual.  This changes only the way the
values are stored, not the way <tt>$*</tt> is parsed, so results may be
unpredictable if the &lsquo;<var>name</var><tt>+</tt>&rsquo; specifier is used inconsistently.
</p>
</dd>
<dt><tt>-E</tt></dt>
<dd><p>This changes the parsing rules to <em>not</em> stop at the first string
that isn&rsquo;t described by one of the <var>spec</var>s.  It can be used to test
for or (if used together with <tt>-D</tt>) extract options and their
arguments, ignoring all other options and arguments that may be in the
positional parameters.
</p>
</dd>
</dl>

<p>For example,
</p>
<div class="example">
<pre class="example">set -- -a -bx -c y -cz baz -cend
zparseopts a=foo b:=bar c+:=bar
</pre></div>

<p>will have the effect of
</p>
<div class="example">
<pre class="example">foo=(-a)
bar=(-b x -c y -c z)
</pre></div>

<p>The arguments from &lsquo;<tt>baz</tt>&rsquo; on will not be used.
</p>
<p>As an example for the <tt>-E</tt> option, consider:
</p>
<div class="example">
<pre class="example">set -- -a x -b y -c z arg1 arg2
zparseopts -E -D b:=bar
</pre></div>

<p>will have the effect of
</p>
<div class="example">
<pre class="example">bar=(-b y)
set -- -a x -c z arg1 arg2
</pre></div>

<p>I.e., the option <tt>-b</tt> and its arguments are taken from the
positional parameters and put into the array <tt>bar</tt>.
</p>
<p>The <tt>-M</tt> option can be used like this:
</p>
<div class="example">
<pre class="example">set -- -a -bx -c y -cz baz -cend
zparseopts -A bar -M a=foo b+: c:=b
</pre></div>

<p>to have the effect of
</p>
<div class="example">
<pre class="example">foo=(-a)
bar=(-a '' -b xyz)
</pre></div>

</dd>
</dl>
<hr>
<table class="header" cellpadding="1" cellspacing="1" border="0">
<tr><td valign="middle" align="left">[<a href="#Zsh-Modules" title="Beginning of this chapter or previous chapter"> &lt;&lt; </a>]</td>
<td valign="middle" align="left">[<a href="Calendar-Function-System.html#Calendar-Function-System" title="Next chapter"> &gt;&gt; </a>]</td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left"> &nbsp; </td>
<td valign="middle" align="left">[<a href="index.html#Top" title="Cover (top) of document">Top</a>]</td>
<td valign="middle" align="left">[<a href="zsh_toc.html#SEC_Contents" title="Table of contents">Contents</a>]</td>
<td valign="middle" align="left">[<a href="Concept-Index.html#Concept-Index" title="Index">Index</a>]</td>
<td valign="middle" align="left">[<a href="zsh_abt.html#SEC_About" title="About (help)"> ? </a>]</td>
</tr></table>
<p>
 <font size="-1">
  This document was generated on <i>February 3, 2019</i> using <a href="http://www.nongnu.org/texi2html/"><i>texi2html 5.0</i></a>.
 </font>
 <br>
<font size="-1">Zsh version 5.7.1, released on February 3, 2019.</font>
</p>
</body>
</html>