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