1ZSHALL(1) General Commands Manual ZSHALL(1)
2
3
4
6 zshall - the Z shell meta-man page
7
9 Because zsh contains many features, the zsh manual has been split into
10 a number of sections. This manual page includes all the separate man‐
11 ual pages in the following order:
12
13 zshroadmap Informal introduction to the manual
14 zshmisc Anything not fitting into the other sections
15 zshexpn Zsh command and parameter expansion
16 zshparam Zsh parameters
17 zshoptions Zsh options
18 zshbuiltins Zsh built-in functions
19 zshzle Zsh command line editing
20 zshcompwid Zsh completion widgets
21 zshcompsys Zsh completion system
22 zshcompctl Zsh completion control
23 zshmodules Zsh loadable modules
24 zshcalsys Zsh built-in calendar functions
25 zshtcpsys Zsh built-in TCP functions
26 zshzftpsys Zsh built-in FTP client
27 zshcontrib Additional zsh functions and utilities
28
30 Zsh is a UNIX command interpreter (shell) usable as an interactive
31 login shell and as a shell script command processor. Of the standard
32 shells, zsh most closely resembles ksh but includes many enhancements.
33 Zsh has command line editing, builtin spelling correction, programmable
34 command completion, shell functions (with autoloading), a history mech‐
35 anism, and a host of other features.
36
38 Zsh was originally written by Paul Falstad <pf@zsh.org>. Zsh is now
39 maintained by the members of the zsh-workers mailing list <zsh-work‐
40 ers@zsh.org>. The development is currently coordinated by Peter
41 Stephenson <pws@zsh.org>. The coordinator can be contacted at <coordi‐
42 nator@zsh.org>, but matters relating to the code should generally go to
43 the mailing list.
44
46 Zsh is available from the following anonymous FTP sites. These mirror
47 sites are kept frequently up to date. The sites marked with (H) may be
48 mirroring ftp.cs.elte.hu instead of the primary site.
49
50 Primary site
51 ftp://ftp.zsh.org/pub/zsh/
52 http://www.zsh.org/pub/zsh/
53
54 Australia
55 ftp://ftp.zsh.org/pub/zsh/
56 http://www.zsh.org/pub/zsh/
57
58 Finland
59 ftp://ftp.funet.fi/pub/unix/shells/zsh/
60
61 Germany
62 ftp://ftp.fu-berlin.de/pub/unix/shells/zsh/ (H)
63 ftp://ftp.gmd.de/packages/zsh/
64 ftp://ftp.uni-trier.de/pub/unix/shell/zsh/
65
66 Hungary
67 ftp://ftp.cs.elte.hu/pub/zsh/
68 http://www.cs.elte.hu/pub/zsh/
69 ftp://ftp.kfki.hu/pub/packages/zsh/
70
71 Israel
72 ftp://ftp.math.technion.ac.il/pub/zsh/
73 http://www.math.technion.ac.il/pub/zsh/
74
75 Japan
76 ftp://ftp.win.ne.jp/pub/shell/zsh/
77
78 Korea
79 ftp://linux.sarang.net/mirror/system/shell/zsh/
80
81 Netherlands
82 ftp://ftp.demon.nl/pub/mirrors/zsh/
83
84 Norway
85 ftp://ftp.uit.no/pub/unix/shells/zsh/
86
87 Poland
88 ftp://sunsite.icm.edu.pl/pub/unix/shells/zsh/
89
90 Romania
91 ftp://ftp.roedu.net/pub/mirrors/ftp.zsh.org/pub/zsh/
92 ftp://ftp.kappa.ro/pub/mirrors/ftp.zsh.org/pub/zsh/
93
94 Slovenia
95 ftp://ftp.siol.net/mirrors/zsh/
96
97 Sweden
98 ftp://ftp.lysator.liu.se/pub/unix/zsh/
99
100 UK
101 ftp://ftp.net.lut.ac.uk/zsh/
102 ftp://sunsite.org.uk/packages/zsh/
103
104 USA
105 http://zsh.open-mirror.com/
106
107 The up-to-date source code is available via anonymous CVS and Git from
108 Sourceforge. See http://sourceforge.net/projects/zsh/ for details. A
109 summary of instructions for the CVS and Git archives can be found at
110 http://zsh.sourceforget.net/.
111
113 Zsh has 3 mailing lists:
114
115 <zsh-announce@zsh.org>
116 Announcements about releases, major changes in the shell and the
117 monthly posting of the Zsh FAQ. (moderated)
118
119 <zsh-users@zsh.org>
120 User discussions.
121
122 <zsh-workers@zsh.org>
123 Hacking, development, bug reports and patches.
124
125 To subscribe or unsubscribe, send mail to the associated administrative
126 address for the mailing list.
127
128 <zsh-announce-subscribe@zsh.org>
129 <zsh-users-subscribe@zsh.org>
130 <zsh-workers-subscribe@zsh.org>
131 <zsh-announce-unsubscribe@zsh.org>
132 <zsh-users-unsubscribe@zsh.org>
133 <zsh-workers-unsubscribe@zsh.org>
134
135 YOU ONLY NEED TO JOIN ONE OF THE MAILING LISTS AS THEY ARE NESTED. All
136 submissions to zsh-announce are automatically forwarded to zsh-users.
137 All submissions to zsh-users are automatically forwarded to zsh-work‐
138 ers.
139
140 If you have problems subscribing/unsubscribing to any of the mailing
141 lists, send mail to <listmaster@zsh.org>. The mailing lists are main‐
142 tained by Karsten Thygesen <karthy@kom.auc.dk>.
143
144 The mailing lists are archived; the archives can be accessed via the
145 administrative addresses listed above. There is also a hypertext ar‐
146 chive, maintained by Geoff Wing <gcw@zsh.org>, available at
147 http://www.zsh.org/mla/.
148
150 Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
151 Stephenson <pws@zsh.org>. It is regularly posted to the newsgroup
152 comp.unix.shell and the zsh-announce mailing list. The latest version
153 can be found at any of the Zsh FTP sites, or at
154 http://www.zsh.org/FAQ/. The contact address for FAQ-related matters
155 is <faqmaster@zsh.org>.
156
158 Zsh has a web page which is located at http://www.zsh.org/. This is
159 maintained by Karsten Thygesen <karthy@zsh.org>, of SunSITE Denmark.
160 The contact address for web-related matters is <webmaster@zsh.org>.
161
163 A userguide is currently in preparation. It is intended to complement
164 the manual, with explanations and hints on issues where the manual can
165 be cabbalistic, hierographic, or downright mystifying (for example, the
166 word `hierographic' does not exist). It can be viewed in its current
167 state at http://zsh.sourceforge.net/Guide/. At the time of writing,
168 chapters dealing with startup files and their contents and the new com‐
169 pletion system were essentially complete.
170
172 A `wiki' website for zsh has been created at http://www.zshwiki.org/.
173 This is a site which can be added to and modified directly by users
174 without any special permission. You can add your own zsh tips and con‐
175 figurations.
176
178 The following flags are interpreted by the shell when invoked to deter‐
179 mine where the shell will read commands from:
180
181 -c Take the first argument as a command to execute, rather than
182 reading commands from a script or standard input. If any fur‐
183 ther arguments are given, the first one is assigned to $0,
184 rather than being used as a positional parameter.
185
186 -i Force shell to be interactive. It is still possible to specify
187 a script to execute.
188
189 -s Force shell to read commands from the standard input. If the -s
190 flag is not present and an argument is given, the first argument
191 is taken to be the pathname of a script to execute.
192
193 If there are any remaining arguments after option processing, and nei‐
194 ther of the options -c or -s was supplied, the first argument is taken
195 as the file name of a script containing shell commands to be executed.
196 If the option PATH_SCRIPT is set, and the file name does not contain a
197 directory path (i.e. there is no `/' in the name), first the current
198 directory and then the command path given by the variable PATH are
199 searched for the script. If the option is not set or the file name
200 contains a `/' it is used directly.
201
202 After the first one or two arguments have been appropriated as
203 described above, the remaining arguments are assigned to the positional
204 parameters.
205
206 For further options, which are common to invocation and the set
207 builtin, see zshoptions(1).
208
209 Options may be specified by name using the -o option. -o acts like a
210 single-letter option, but takes a following string as the option name.
211 For example,
212
213 zsh -x -o shwordsplit scr
214
215 runs the script scr, setting the XTRACE option by the corresponding
216 letter `-x' and the SH_WORD_SPLIT option by name. Options may be
217 turned off by name by using +o instead of -o. -o can be stacked up
218 with preceding single-letter options, so for example `-xo shwordsplit'
219 or `-xoshwordsplit' is equivalent to `-x -o shwordsplit'.
220
221 Options may also be specified by name in GNU long option style,
222 `--option-name'. When this is done, `-' characters in the option name
223 are permitted: they are translated into `_', and thus ignored. So, for
224 example, `zsh --sh-word-split' invokes zsh with the SH_WORD_SPLIT
225 option turned on. Like other option syntaxes, options can be turned
226 off by replacing the initial `-' with a `+'; thus `+-sh-word-split' is
227 equivalent to `--no-sh-word-split'. Unlike other option syntaxes,
228 GNU-style long options cannot be stacked with any other options, so for
229 example `-x-shwordsplit' is an error, rather than being treated like
230 `-x --shwordsplit'.
231
232 The special GNU-style option `--version' is handled; it sends to stan‐
233 dard output the shell's version information, then exits successfully.
234 `--help' is also handled; it sends to standard output a list of options
235 that can be used when invoking the shell, then exits successfully.
236
237 Option processing may be finished, allowing following arguments that
238 start with `-' or `+' to be treated as normal arguments, in two ways.
239 Firstly, a lone `-' (or `+') as an argument by itself ends option pro‐
240 cessing. Secondly, a special option `--' (or `+-'), which may be spec‐
241 ified on its own (which is the standard POSIX usage) or may be stacked
242 with preceding options (so `-x-' is equivalent to `-x --'). Options
243 are not permitted to be stacked after `--' (so `-x-f' is an error), but
244 note the GNU-style option form discussed above, where `--shwordsplit'
245 is permitted and does not end option processing.
246
247 Except when the sh/ksh emulation single-letter options are in effect,
248 the option `-b' (or `+b') ends option processing. `-b' is like `--',
249 except that further single-letter options can be stacked after the `-b'
250 and will take effect as normal.
251
253 Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respec‐
254 tively; more precisely, it looks at the first letter of the name by
255 which it was invoked, excluding any initial `r' (assumed to stand for
256 `restricted'), and if that is `b', `s' or `k' it will emulate sh or
257 ksh. Furthermore, if invoked as su (which happens on certain systems
258 when the shell is executed by the su command), the shell will try to
259 find an alternative name from the SHELL environment variable and per‐
260 form emulation based on that.
261
262 In sh and ksh compatibility modes the following parameters are not spe‐
263 cial and not initialized by the shell: ARGC, argv, cdpath, fignore,
264 fpath, HISTCHARS, mailpath, MANPATH, manpath, path, prompt, PROMPT,
265 PROMPT2, PROMPT3, PROMPT4, psvar, status, watch.
266
267 The usual zsh startup/shutdown scripts are not executed. Login shells
268 source /etc/profile followed by $HOME/.profile. If the ENV environment
269 variable is set on invocation, $ENV is sourced after the profile
270 scripts. The value of ENV is subjected to parameter expansion, command
271 substitution, and arithmetic expansion before being interpreted as a
272 pathname. Note that the PRIVILEGED option also affects the execution
273 of startup files.
274
275 The following options are set if the shell is invoked as sh or ksh:
276 NO_BAD_PATTERN, NO_BANG_HIST, NO_BG_NICE, NO_EQUALS, NO_FUNC‐
277 TION_ARGZERO, GLOB_SUBST, NO_GLOBAL_EXPORT, NO_HUP, INTERACTIVE_COM‐
278 MENTS, KSH_ARRAYS, NO_MULTIOS, NO_NOMATCH, NO_NOTIFY, POSIX_BUILTINS,
279 NO_PROMPT_PERCENT, RM_STAR_SILENT, SH_FILE_EXPANSION, SH_GLOB,
280 SH_OPTION_LETTERS, SH_WORD_SPLIT. Additionally the BSD_ECHO and
281 IGNORE_BRACES options are set if zsh is invoked as sh. Also, the
282 KSH_OPTION_PRINT, LOCAL_OPTIONS, PROMPT_BANG, PROMPT_SUBST and SIN‐
283 GLE_LINE_ZLE options are set if zsh is invoked as ksh.
284
286 When the basename of the command used to invoke zsh starts with the
287 letter `r' or the `-r' command line option is supplied at invocation,
288 the shell becomes restricted. Emulation mode is determined after
289 stripping the letter `r' from the invocation name. The following are
290 disabled in restricted mode:
291
292 · changing directories with the cd builtin
293
294 · changing or unsetting the PATH, path, MODULE_PATH, module_path,
295 SHELL, HISTFILE, HISTSIZE, GID, EGID, UID, EUID, USERNAME,
296 LD_LIBRARY_PATH, LD_AOUT_LIBRARY_PATH, LD_PRELOAD and
297 LD_AOUT_PRELOAD parameters
298
299 · specifying command names containing /
300
301 · specifying command pathnames using hash
302
303 · redirecting output to files
304
305 · using the exec builtin command to replace the shell with another
306 command
307
308 · using jobs -Z to overwrite the shell process' argument and envi‐
309 ronment space
310
311 · using the ARGV0 parameter to override argv[0] for external com‐
312 mands
313
314 · turning off restricted mode with set +r or unsetopt RESTRICTED
315
316 These restrictions are enforced after processing the startup files.
317 The startup files should set up PATH to point to a directory of com‐
318 mands which can be safely invoked in the restricted environment. They
319 may also add further restrictions by disabling selected builtins.
320
321 Restricted mode can also be activated any time by setting the
322 RESTRICTED option. This immediately enables all the restrictions
323 described above even if the shell still has not processed all startup
324 files.
325
327 Commands are first read from /etc/zshenv; this cannot be overridden.
328 Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the
329 former affects all startup files, while the second only affects global
330 startup files (those shown here with an path starting with a /). If
331 one of the options is unset at any point, any subsequent startup
332 file(s) of the corresponding type will not be read. It is also possi‐
333 ble for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and
334 GLOBAL_RCS are set by default.
335
336 Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login
337 shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro‐
338 file. Then, if the shell is interactive, commands are read from
339 /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login
340 shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
341
342 When a login shell exits, the files $ZDOTDIR/.zlogout and then
343 /etc/zlogout are read. This happens with either an explicit exit via
344 the exit or logout commands, or an implicit exit by reading end-of-file
345 from the terminal. However, if the shell terminates due to exec'ing
346 another process, the logout files are not read. These are also
347 affected by the RCS and GLOBAL_RCS options. Note also that the RCS
348 option affects the saving of history files, i.e. if RCS is unset when
349 the shell exits, no history file will be saved.
350
351 If ZDOTDIR is unset, HOME is used instead. Files listed above as being
352 in /etc may be in another directory, depending on the installation.
353
354 As /etc/zshenv is run for all instances of zsh, it is important that it
355 be kept as small as possible. In particular, it is a good idea to put
356 code that does not need to be run for every single shell behind a test
357 of the form `if [[ -o rcs ]]; then ...' so that it will not be executed
358 when zsh is invoked with the `-f' option.
359
360 Any of these files may be pre-compiled with the zcompile builtin com‐
361 mand (see zshbuiltins(1)). If a compiled file exists (named for the
362 original file plus the .zwc extension) and it is newer than the origi‐
363 nal file, the compiled file will be used instead.
364
365
366
367ZSHROADMAP(1) General Commands Manual ZSHROADMAP(1)
368
369
370
372 zshroadmap - informal introduction to the zsh manual
373
374 The Zsh Manual, like the shell itself, is large and often complicated.
375 This section of the manual provides some pointers to areas of the shell
376 that are likely to be of particular interest to new users, and indi‐
377 cates where in the rest of the manual the documentation is to be found.
378
380 When it starts, the shell reads commands from various files. These can
381 be created or edited to customize the shell. See the section
382 Startup/Shutdown Files in zsh(1).
383
384 If no personal initialization files exist for the current user, a func‐
385 tion is run to help you change some of the most common settings. It
386 won't appear if your administrator has disabled the zsh/newuser module.
387 The function is designed to be self-explanatory. You can run it by
388 hand with `autoload -Uz zsh-newuser-install; zsh-newuser-install -f'.
389 See also the section User Configuration Functions in zshcontrib(1).
390
392 Interaction with the shell uses the builtin Zsh Line Editor, ZLE. This
393 is described in detail in zshzle(1).
394
395 The first decision a user must make is whether to use the Emacs or Vi
396 editing mode as the keys for editing are substantially different.
397 Emacs editing mode is probably more natural for beginners and can be
398 selected explicitly with the command bindkey -e.
399
400 A history mechanism for retrieving previously typed lines (most simply
401 with the Up or Down arrow keys) is available; note that, unlike other
402 shells, zsh will not save these lines when the shell exits unless you
403 set appropriate variables, and the number of history lines retained by
404 default is quite small (30 lines). See the description of the shell
405 variables (referred to in the documentation as parameters) HISTFILE,
406 HISTSIZE and SAVEHIST in zshparam(1).
407
408 The shell now supports the UTF-8 character set (and also others if sup‐
409 ported by the operating system). This is (mostly) handled transpar‐
410 ently by the shell, but the degree of support in terminal emulators is
411 variable. There is some discussion of this in the shell FAQ,
412 http://zsh.dotsrc.org/FAQ/ . Note in particular that for combining
413 characters to be handled the option COMBINING_CHARS needs to be set.
414 Because the shell is now more sensitive to the definition of the char‐
415 acter set, note that if you are upgrading from an older version of the
416 shell you should ensure that the appropriate variable, either LANG (to
417 affect all aspects of the shell's operation) or LC_CTYPE (to affect
418 only the handling of character sets) is set to an appropriate value.
419 This is true even if you are using a single-byte character set includ‐
420 ing extensions of ASCII such as ISO-8859-1 or ISO-8859-15. See the
421 description of LC_CTYPE in zshparam(1).
422
423 Completion
424 Completion is a feature present in many shells. It allows the user to
425 type only a part (usually the prefix) of a word and have the shell fill
426 in the rest. The completion system in zsh is programmable. For exam‐
427 ple, the shell can be set to complete email addresses in arguments to
428 the mail command from your ~/.abook/addressbook; usernames, hostnames,
429 and even remote paths in arguments to scp, and so on. Anything that
430 can be written in or glued together with zsh can be the source of what
431 the line editor offers as possible completions.
432
433 Zsh has two completion systems, an old, so called compctl completion
434 (named after the builtin command that serves as its complete and only
435 user interface), and a new one, referred to as compsys, organized as
436 library of builtin and user-defined functions. The two systems differ
437 in their interface for specifying the completion behavior. The new
438 system is more customizable and is supplied with completions for many
439 commonly used commands; it is therefore to be preferred.
440
441 The completion system must be enabled explicitly when the shell starts.
442 For more information see zshcompsys(1).
443
444 Extending the line editor
445 Apart from completion, the line editor is highly extensible by means of
446 shell functions. Some useful functions are provided with the shell;
447 they provide facilities such as:
448
449 insert-composed-char
450 composing characters not found on the keyboard
451
452 match-words-by-style
453 configuring what the line editor considers a word when moving or
454 deleting by word
455
456 history-beginning-search-backward-end, etc.
457 alternative ways of searching the shell history
458
459 replace-string, replace-pattern
460 functions for replacing strings or patterns globally in the com‐
461 mand line
462
463 edit-command-line
464 edit the command line with an external editor.
465
466 See the section `ZLE Functions' in zshcontrib(1) for descriptions of
467 these.
468
470 The shell has a large number of options for changing its behaviour.
471 These cover all aspects of the shell; browsing the full documentation
472 is the only good way to become acquainted with the many possibilities.
473 See zshoptions(1).
474
476 The shell has a rich set of patterns which are available for file
477 matching (described in the documentation as `filename generation' and
478 also known for historical reasons as `globbing') and for use when pro‐
479 gramming. These are described in the section `Filename Generation' in
480 zshexpn(1).
481
482 Of particular interest are the following patterns that are not commonly
483 supported by other systems of pattern matching:
484
485 ** for matching over multiple directories
486
487 ~, ^ the ability to exclude patterns from matching when the
488 EXTENDED_GLOB option is set
489
490 (...) glob qualifiers, included in parentheses at the end of the pat‐
491 tern, which select files by type (such as directories) or
492 attribute (such as size).
493
495 Although the syntax of zsh is in ways similar to the Korn shell, and
496 therefore more remotely to the original UNIX shell, the Bourne shell,
497 its default behaviour does not entirely correspond to those shells.
498 General shell syntax is introduced in the section `Shell Grammar' in
499 zshmisc(1).
500
501 One commonly encountered difference is that variables substituted onto
502 the command line are not split into words. See the description of the
503 shell option SH_WORD_SPLIT in the section `Parameter Expansion' in zsh‐
504 expn(1). In zsh, you can either explicitly request the splitting (e.g.
505 ${=foo}) or use an array when you want a variable to expand to more
506 than one word. See the section `Array Parameters' in zshparam(1).
507
509 The most convenient way of adding enhancements to the shell is typi‐
510 cally by writing a shell function and arranging for it to be
511 autoloaded. Functions are described in the section `Functions' in zsh‐
512 misc(1). Users changing from the C shell and its relatives should
513 notice that aliases are less used in zsh as they don't perform argument
514 substitution, only simple text replacement.
515
516 A few general functions, other than those for the line editor described
517 above, are provided with the shell and are described in zshcontrib(1).
518 Features include:
519
520 promptinit
521 a prompt theme system for changing prompts easily, see the sec‐
522 tion `Prompt Themes'
523
524
525 zsh-mime-setup
526 a MIME-handling system which dispatches commands according to
527 the suffix of a file as done by graphical file managers
528
529 zcalc a calculator
530
531 zargs a version of xargs that makes the find command redundant
532
533 zmv a command for renaming files by means of shell patterns.
534
535
536
537ZSHALL(1) General Commands Manual ZSHALL(1)
538
539
540
542 $ZDOTDIR/.zshenv
543 $ZDOTDIR/.zprofile
544 $ZDOTDIR/.zshrc
545 $ZDOTDIR/.zlogin
546 $ZDOTDIR/.zlogout
547 ${TMPPREFIX}* (default is /tmp/zsh*)
548 /etc/zshenv
549 /etc/zprofile
550 /etc/zshrc
551 /etc/zlogin
552 /etc/zlogout (installation-specific - /etc is the default)
553
555 sh(1), csh(1), tcsh(1), rc(1), bash(1), ksh(1)
556
557 IEEE Standard for information Technology - Portable Operating System
558 Interface (POSIX) - Part 2: Shell and Utilities, IEEE Inc, 1993, ISBN
559 1-55937-255-9.
560
561
562
563zsh 4.3.11 December 20, 2010 ZSHALL(1)