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