1ZSH(1) General Commands Manual ZSH(1)
2
3
4
6 zsh - the Z shell
7
9 Because zsh contains many features, the zsh manual has been split into
10 a number of sections:
11
12 zsh Zsh overview (this section)
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 zshall Meta-man page containing all of the above
29
31 Zsh is a UNIX command interpreter (shell) usable as an interactive lo‐
32 gin 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 de‐
35 fault 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 in‐
58 structions for the archive can be found at http://zsh.sourceforge.net/.
59
61 Zsh has 3 mailing lists:
62
63 <zsh-announce@zsh.org>
64 Announcements about releases, major changes in the shell and the
65 monthly posting of the Zsh FAQ. (moderated)
66
67 <zsh-users@zsh.org>
68 User discussions.
69
70 <zsh-workers@zsh.org>
71 Hacking, development, bug reports and patches.
72
73 To subscribe or unsubscribe, send mail to the associated administrative
74 address for the mailing list.
75
76 <zsh-announce-subscribe@zsh.org>
77 <zsh-users-subscribe@zsh.org>
78 <zsh-workers-subscribe@zsh.org>
79 <zsh-announce-unsubscribe@zsh.org>
80 <zsh-users-unsubscribe@zsh.org>
81 <zsh-workers-unsubscribe@zsh.org>
82
83 YOU ONLY NEED TO JOIN ONE OF THE MAILING LISTS AS THEY ARE NESTED. All
84 submissions to zsh-announce are automatically forwarded to zsh-users.
85 All submissions to zsh-users are automatically forwarded to zsh-work‐
86 ers.
87
88 If you have problems subscribing/unsubscribing to any of the mailing
89 lists, send mail to <listmaster@zsh.org>. The mailing lists are main‐
90 tained by Karsten Thygesen <karthy@kom.auc.dk>.
91
92 The mailing lists are archived; the archives can be accessed via the
93 administrative addresses listed above. There is also a hypertext ar‐
94 chive, maintained by Geoff Wing <gcw@zsh.org>, available at
95 https://www.zsh.org/mla/.
96
98 Zsh has a list of Frequently Asked Questions (FAQ), maintained by Peter
99 Stephenson <pws@zsh.org>. It is regularly posted to the newsgroup
100 comp.unix.shell and the zsh-announce mailing list. The latest version
101 can be found at any of the Zsh FTP sites, or at
102 http://www.zsh.org/FAQ/. The contact address for FAQ-related matters
103 is <faqmaster@zsh.org>.
104
106 Zsh has a web page which is located at https://www.zsh.org/. This is
107 maintained by Karsten Thygesen <karthy@zsh.org>, of SunSITE Denmark.
108 The contact address for web-related matters is <webmaster@zsh.org>.
109
111 A userguide is currently in preparation. It is intended to complement
112 the manual, with explanations and hints on issues where the manual can
113 be cabbalistic, hierographic, or downright mystifying (for example, the
114 word `hierographic' does not exist). It can be viewed in its current
115 state at http://zsh.sourceforge.net/Guide/. At the time of writing,
116 chapters dealing with startup files and their contents and the new com‐
117 pletion system were essentially complete.
118
120 The following flags are interpreted by the shell when invoked to deter‐
121 mine where the shell will read commands from:
122
123 -c Take the first argument as a command to execute, rather than
124 reading commands from a script or standard input. If any fur‐
125 ther arguments are given, the first one is assigned to $0,
126 rather than being used as a positional parameter.
127
128 -i Force shell to be interactive. It is still possible to specify
129 a script to execute.
130
131 -s Force shell to read commands from the standard input. If the -s
132 flag is not present and an argument is given, the first argument
133 is taken to be the pathname of a script to execute.
134
135 If there are any remaining arguments after option processing, and nei‐
136 ther of the options -c or -s was supplied, the first argument is taken
137 as the file name of a script containing shell commands to be executed.
138 If the option PATH_SCRIPT is set, and the file name does not contain a
139 directory path (i.e. there is no `/' in the name), first the current
140 directory and then the command path given by the variable PATH are
141 searched for the script. If the option is not set or the file name
142 contains a `/' it is used directly.
143
144 After the first one or two arguments have been appropriated as de‐
145 scribed above, the remaining arguments are assigned to the positional
146 parameters.
147
148 For further options, which are common to invocation and the set
149 builtin, see zshoptions(1).
150
151 The long option `--emulate' followed (in a separate word) by an emula‐
152 tion mode may be passed to the shell. The emulation modes are those
153 described for the emulate builtin, see zshbuiltins(1). The `--emulate'
154 option must precede any other options (which might otherwise be over‐
155 ridden), but following options are honoured, so may be used to modify
156 the requested emulation mode. Note that certain extra steps are taken
157 to ensure a smooth emulation when this option is used compared with the
158 emulate command within the shell: for example, variables that conflict
159 with POSIX usage such as path are not defined within the shell.
160
161 Options may be specified by name using the -o option. -o acts like a
162 single-letter option, but takes a following string as the option name.
163 For example,
164
165 zsh -x -o shwordsplit scr
166
167 runs the script scr, setting the XTRACE option by the corresponding
168 letter `-x' and the SH_WORD_SPLIT option by name. Options may be
169 turned off by name by using +o instead of -o. -o can be stacked up
170 with preceding single-letter options, so for example `-xo shwordsplit'
171 or `-xoshwordsplit' is equivalent to `-x -o shwordsplit'.
172
173 Options may also be specified by name in GNU long option style, `--op‐
174 tion-name'. When this is done, `-' characters in the option name are
175 permitted: they are translated into `_', and thus ignored. So, for ex‐
176 ample, `zsh --sh-word-split' invokes zsh with the SH_WORD_SPLIT option
177 turned on. Like other option syntaxes, options can be turned off by
178 replacing the initial `-' with a `+'; thus `+-sh-word-split' is equiva‐
179 lent to `--no-sh-word-split'. Unlike other option syntaxes, GNU-style
180 long options cannot be stacked with any other options, so for example
181 `-x-shwordsplit' is an error, rather than being treated like `-x
182 --shwordsplit'.
183
184 The special GNU-style option `--version' is handled; it sends to stan‐
185 dard output the shell's version information, then exits successfully.
186 `--help' is also handled; it sends to standard output a list of options
187 that can be used when invoking the shell, then exits successfully.
188
189 Option processing may be finished, allowing following arguments that
190 start with `-' or `+' to be treated as normal arguments, in two ways.
191 Firstly, a lone `-' (or `+') as an argument by itself ends option pro‐
192 cessing. Secondly, a special option `--' (or `+-'), which may be spec‐
193 ified on its own (which is the standard POSIX usage) or may be stacked
194 with preceding options (so `-x-' is equivalent to `-x --'). Options
195 are not permitted to be stacked after `--' (so `-x-f' is an error), but
196 note the GNU-style option form discussed above, where `--shwordsplit'
197 is permitted and does not end option processing.
198
199 Except when the sh/ksh emulation single-letter options are in effect,
200 the option `-b' (or `+b') ends option processing. `-b' is like `--',
201 except that further single-letter options can be stacked after the `-b'
202 and will take effect as normal.
203
205 Zsh tries to emulate sh or ksh when it is invoked as sh or ksh respec‐
206 tively; more precisely, it looks at the first letter of the name by
207 which it was invoked, excluding any initial `r' (assumed to stand for
208 `restricted'), and if that is `b', `s' or `k' it will emulate sh or
209 ksh. Furthermore, if invoked as su (which happens on certain systems
210 when the shell is executed by the su command), the shell will try to
211 find an alternative name from the SHELL environment variable and per‐
212 form emulation based on that.
213
214 In sh and ksh compatibility modes the following parameters are not spe‐
215 cial and not initialized by the shell: ARGC, argv, cdpath, fignore,
216 fpath, HISTCHARS, mailpath, MANPATH, manpath, path, prompt, PROMPT,
217 PROMPT2, PROMPT3, PROMPT4, psvar, status, watch.
218
219 The usual zsh startup/shutdown scripts are not executed. Login shells
220 source /etc/profile followed by $HOME/.profile. If the ENV environment
221 variable is set on invocation, $ENV is sourced after the profile
222 scripts. The value of ENV is subjected to parameter expansion, command
223 substitution, and arithmetic expansion before being interpreted as a
224 pathname. Note that the PRIVILEGED option also affects the execution
225 of startup files.
226
227 The following options are set if the shell is invoked as sh or ksh:
228 NO_BAD_PATTERN, NO_BANG_HIST, NO_BG_NICE, NO_EQUALS, NO_FUNC‐
229 TION_ARGZERO, GLOB_SUBST, NO_GLOBAL_EXPORT, NO_HUP, INTERACTIVE_COM‐
230 MENTS, KSH_ARRAYS, NO_MULTIOS, NO_NOMATCH, NO_NOTIFY, POSIX_BUILTINS,
231 NO_PROMPT_PERCENT, RM_STAR_SILENT, SH_FILE_EXPANSION, SH_GLOB, SH_OP‐
232 TION_LETTERS, SH_WORD_SPLIT. Additionally the BSD_ECHO and IG‐
233 NORE_BRACES options are set if zsh is invoked as sh. Also, the KSH_OP‐
234 TION_PRINT, LOCAL_OPTIONS, PROMPT_BANG, PROMPT_SUBST and SIN‐
235 GLE_LINE_ZLE options are set if zsh is invoked as ksh.
236
238 When the basename of the command used to invoke zsh starts with the
239 letter `r' or the `-r' command line option is supplied at invocation,
240 the shell becomes restricted. Emulation mode is determined after
241 stripping the letter `r' from the invocation name. The following are
242 disabled in restricted mode:
243
244 • changing directories with the cd builtin
245
246 • changing or unsetting the EGID, EUID, GID, HISTFILE, HISTSIZE,
247 IFS, LD_AOUT_LIBRARY_PATH, LD_AOUT_PRELOAD, LD_LIBRARY_PATH,
248 LD_PRELOAD, MODULE_PATH, module_path, PATH, path, SHELL, UID and
249 USERNAME parameters
250
251 • specifying command names containing /
252
253 • specifying command pathnames using hash
254
255 • redirecting output to files
256
257 • using the exec builtin command to replace the shell with another
258 command
259
260 • using jobs -Z to overwrite the shell process' argument and envi‐
261 ronment space
262
263 • using the ARGV0 parameter to override argv[0] for external com‐
264 mands
265
266 • turning off restricted mode with set +r or unsetopt RESTRICTED
267
268 These restrictions are enforced after processing the startup files.
269 The startup files should set up PATH to point to a directory of com‐
270 mands which can be safely invoked in the restricted environment. They
271 may also add further restrictions by disabling selected builtins.
272
273 Restricted mode can also be activated any time by setting the RE‐
274 STRICTED option. This immediately enables all the restrictions de‐
275 scribed above even if the shell still has not processed all startup
276 files.
277
278 A shell Restricted Mode is an outdated way to restrict what users may
279 do: modern systems have better, safer and more reliable ways to con‐
280 fine user actions, such as chroot jails, containers and zones.
281
282 A restricted shell is very difficult to implement safely. The feature
283 may be removed in a future version of zsh.
284
285 It is important to realise that the restrictions only apply to the
286 shell, not to the commands it runs (except for some shell builtins).
287 While a restricted shell can only run the restricted list of commands
288 accessible via the predefined `PATH' variable, it does not prevent
289 those commands from running any other command.
290
291 As an example, if `env' is among the list of allowed commands, then it
292 allows the user to run any command as `env' is not a shell builtin com‐
293 mand and can run arbitrary executables.
294
295 So when implementing a restricted shell framework it is important to be
296 fully aware of what actions each of the allowed commands or features
297 (which may be regarded as modules) can perform.
298
299 Many commands can have their behaviour affected by environment vari‐
300 ables. Except for the few listed above, zsh does not restrict the set‐
301 ting of environment variables.
302
303 If a `perl', `python', `bash', or other general purpose interpreted
304 script it treated as a restricted command, the user can work around the
305 restriction by setting specially crafted `PERL5LIB', `PYTHONPATH',
306 `BASHENV' (etc.) environment variables. On GNU systems, any command can
307 be made to run arbitrary code when performing character set conversion
308 (including zsh itself) by setting a `GCONV_PATH' environment variable.
309 Those are only a few examples.
310
311 Bear in mind that, contrary to some other shells, `readonly' is not a
312 security feature in zsh as it can be undone and so cannot be used to
313 mitigate the above.
314
315 A restricted shell only works if the allowed commands are few and care‐
316 fully written so as not to grant more access to users than intended.
317 It is also important to restrict what zsh module the user may load as
318 some of them, such as `zsh/system', `zsh/mapfile' and `zsh/files', al‐
319 low bypassing most of the restrictions.
320
322 Commands are first read from /etc/zshenv; this cannot be overridden.
323 Subsequent behaviour is modified by the RCS and GLOBAL_RCS options; the
324 former affects all startup files, while the second only affects global
325 startup files (those shown here with an path starting with a /). If
326 one of the options is unset at any point, any subsequent startup
327 file(s) of the corresponding type will not be read. It is also possi‐
328 ble for a file in $ZDOTDIR to re-enable GLOBAL_RCS. Both RCS and
329 GLOBAL_RCS are set by default.
330
331 Commands are then read from $ZDOTDIR/.zshenv. If the shell is a login
332 shell, commands are read from /etc/zprofile and then $ZDOTDIR/.zpro‐
333 file. Then, if the shell is interactive, commands are read from
334 /etc/zshrc and then $ZDOTDIR/.zshrc. Finally, if the shell is a login
335 shell, /etc/zlogin and $ZDOTDIR/.zlogin are read.
336
337 When a login shell exits, the files $ZDOTDIR/.zlogout and then /etc/zl‐
338 ogout are read. This happens with either an explicit exit via the exit
339 or logout commands, or an implicit exit by reading end-of-file from the
340 terminal. However, if the shell terminates due to exec'ing another
341 process, the logout files are not read. These are also affected by the
342 RCS and GLOBAL_RCS options. Note also that the RCS option affects the
343 saving of history files, i.e. if RCS is unset when the shell exits, no
344 history file will be saved.
345
346 If ZDOTDIR is unset, HOME is used instead. Files listed above as being
347 in /etc may be in another directory, depending on the installation.
348
349 As /etc/zshenv is run for all instances of zsh, it is important that it
350 be kept as small as possible. In particular, it is a good idea to put
351 code that does not need to be run for every single shell behind a test
352 of the form `if [[ -o rcs ]]; then ...' so that it will not be executed
353 when zsh is invoked with the `-f' option.
354
355 Any of these files may be pre-compiled with the zcompile builtin com‐
356 mand (see zshbuiltins(1)). If a compiled file exists (named for the
357 original file plus the .zwc extension) and it is newer than the origi‐
358 nal file, the compiled file will be used instead.
359
361 $ZDOTDIR/.zshenv
362 $ZDOTDIR/.zprofile
363 $ZDOTDIR/.zshrc
364 $ZDOTDIR/.zlogin
365 $ZDOTDIR/.zlogout
366 ${TMPPREFIX}* (default is /tmp/zsh*)
367 /etc/zshenv
368 /etc/zprofile
369 /etc/zshrc
370 /etc/zlogin
371 /etc/zlogout (installation-specific - /etc is the default)
372
374 sh(1), csh(1), tcsh(1), rc(1), bash(1), ksh(1), zshall(1), zsh‐
375 builtins(1), zshcalsys(1), zshcompwid(1), zshcompsys(1), zshcompctl(1),
376 zshcontrib(1), zshexpn(1), zshmisc(1), zshmodules(1), zshoptions(1),
377 zshparam(1), zshroadmap(1), zshtcpsys(1), zshzftpsys(1), zshzle(1)
378
379 IEEE Standard for information Technology - Portable Operating System
380 Interface (POSIX) - Part 2: Shell and Utilities, IEEE Inc, 1993, ISBN
381 1-55937-255-9.
382
383
384
385zsh 5.8.1 February 12, 2022 ZSH(1)