Zsh
Mirror of the Z shell source code repository.
Install / Use
/learn @zsh-users/ZshREADME
THE Z SHELL (ZSH)
Version
This is version 5.10 of the shell. This is a security and feature release. There are several visible improvements since 5.9, as well as bug fixes. All zsh installations are encouraged to upgrade as soon as possible.
Note in particular the changes highlighted under "Incompatibilities since 5.9" below. See NEWS for more information.
Installing Zsh
The instructions for compiling zsh are in the file INSTALL. You should also check the file MACHINES in the top directory to see if there are any special instructions for your particular architecture.
Note in particular the zsh/newuser module that guides new users through setting basic shell options without the administrator's intervention. This is turned on by default. See the section AUTOMATIC NEW USER CONFIGURATION in INSTALL for configuration information.
Features
Zsh is a shell with lots of features. For a list of some of these, see the file FEATURES, and for the latest changes see NEWS. For more details, see the documentation.
Incompatibilities since 5.9
The line editor's default keymap is now the "emacs" keymap regardless of the value of the environment variables $VISUAL and $EDITOR. This only affects you if your $VISUAL or $EDITOR environment variable is set to a value that contains the string "vi". To get the previous behaviour, add
bindkey -v
or, if your $VISUAL and $EDITOR environment variables vary,
if [[ ${VISUAL} == *vi* || ${EDITOR} == *vi* ]]; then
bindkey -v
else
bindkey -e
fi
to your .zshrc file. These snippets are compatible with previous versions of the shell.
The ERR_EXIT and ERR_RETURN options were refined to be more self-
consistent and better aligned with the POSIX-2017 specification of
set -e:
-
Function calls or anonymous functions prefixed with
!now never trigger exit or return. Negated function calls or anonymous functions used to trigger exit or return if ERR_EXIT or ERR_RETURN was set and the function call or anonymous function returned a zero exit status. Example:setopt ERR_EXIT f() { true } ! f echo "This is printed only since 5.10."
-
The
alwayscommand now ignores ERR_EXIT and ERR_RETURN, as other complex commands do, if its exit status comes from a command executed while the option is ignored. Example:setopt ERR_EXIT { false && true } always { echo "This was and still is printed." } echo "This is printed only since 5.10."
-
Function calls, anonymous functions, and the
eval,., andsourcebuiltins now never ignore ERR_EXIT and ERR_RETURN on their own. These commands used to ignore ERR_EXIT and ERR_RETURN if their result came from a complex command (if, for, ...) whose result came from a command executed while the option is ignored. Example:setopt ERR_EXIT f() { if true; then false && true; fi } f echo "This is printed only prior to 5.10."
-
The
&&and||operators now always ignore ERR_RETURN in their left operand. Until this version, the operators failed to ignore ERR_RETURN in their left operand if they were executed as part of a function call or an anonymous function that was itself executed in a context where ERR_RETURN is ignored. Example:setopt ERR_RETURN f() { { false; echo "This is printed only since 5.10." } || true } if f; then true; fi
PCRE support is now PCRE2.
Parameter names may begin with a "." and follow a relaxed implementation
of ksh namespace syntax. Expansion of such parameters must use braces,
that is, in ${.param.name} form. Parameters so named are excluded from
typeset and set output unless explicitly listed in typeset arguments
or matched by a pattern with typeset -m.
Interpretation of exclusion-patterns following alternation-patterns has
been rationalised. This means for example that [[ ab = (|a*)~^(*b) ]]
is true where previously it was false.
Improvements to handling of terminal colors and attributes in prompts
may change the behavior of some prompt sequences, most notably in
cases where esq=${(%)...} is used to capture an escape sequence.
The which and functions commands output function definitions in a
format independent of the MULTI_FUNC_DEF option.
Math context no longer interprets a leading underscore as part of a numeric constant.
Nul and characters greater than \x77 are correctly handled by read -d.
Return values of sysopen from the zsh/system module have been updated
to be more similar to other commands in that module.
Tied parameters created with the zsh/db/gdbm module may not be re-tied as locals in nested function scope. This prevents database corruption when a function scope ends.
Incompatibilities between 5.8.1 and 5.9
compinit: A "y" response to the "Ignore ... and continue?" prompt removes insecure elements from the set of completion functions, where previously it ignored the compaudit result and included all elements.
Build-time change: The default value of the --enable-gdbm configure argument has changed from "yes" to "no". Thus, the zsh/db/gdbm module will not be built unless --enable-gdbm is passed explicitly.
vcs_info quilt: The value of the 'quiltcommand' style used to be taken for the name of an external command. Now it may also be a shell function. Normal command word precedence rules apply, so if you have a function and a command with the same name, the function will be used.
The "function" reserved word, used to define functions, gained a new -T option. That affects syntaxes such as:
-
"function -T { ... }". It used to define a function named "-T". It now defines and executes an anonymous function with single-level tracing enabled --- same as "function f { ... }; functions -T f; f", but without naming the function.
-
"function -T foo { ... }". It used to define two functions, named "-T" and "foo" (see the MULTI_FUNC_DEF option). It now defines a function "foo" with tracing enabled.
-
"function -- { ... }". It used to define a function named "--". It now defines and executes an anonymous function. The "--" is taken to be an end-of-options guard (same as "ls --").
The sh-compatible function definition syntax, "f() { ... }", is unchanged.
The time-out (-t) value given to zsh/system's zsystem flock command is
now limited to 2^30-1 seconds (= a little over 34 years).
zstyle: For background, recall that the zstyle builtin associates styles with values for particular contexts, and when a context (such as ':foo:bar:baz') is matched by multiple patterns (such as ':foo:' and ':foo:bar:'), the style's value for the more specific of the patterns is used. In zsh 5.8 and earlier the determination of which pattern is "more specific" used semantics slightly different to those the documentation promised. The implementation was changed to match the documentation. The upshot of this is that if you set a single style in multiple contexts, zsh 5.9 may use the values set for a pattern other than the one zsh 5.8 used. For example, if you do zstyle ':foo:bar:' style value1 zstyle ':foo::baz:' style value2 and the style is looked up under a context that both patterns match (e.g., :foo:bar:baz:qux), zsh 5.9 will use value2 -- which is consistent with the documentation of both 5.8 and 5.9 -- but zsh 5.8 will use value1. If this affects you, make the implied colons in the first pattern explicit, as in: zstyle ':foo:bar::' style value1 zstyle ':foo::baz:*' style value2 This will use value1 in both 5.8 and 5.9.
Elements of the region_highlight array have gained a fourth space-separated field. Code written against 5.9 that sets the new field may break under 5.8: for example, the element "0 20 bold memo=foo", which is valid under 5.9, would not work under 5.8. (Under the hood, 5.8 does not recognize the space as terminating the highlighting specification.) On the other hand, code that does not set the new, fourth field will continue to work under both 5.8 and 5.9. (As it happens, adding a comma after "bold" will make both 5.8 and 5.9 do the right thing, but this should be viewed as an unsupported hack.)
The XTRACE option is now disabled while running user-defined completion widgets. See NEWS.
emulate sh: When zsh emulates sh, the final command in a pipeline is now run in a subshell. This differs from the behavior in the native (zsh) mode, but is consistent with most other sh implementations.
The export and readonly builtins now ignore the -p option when there are operands given and POSIX_BUILTINS is enabled. This more closely matches the behaviour of bash and ksh.
getopts now calculates OPTIND in a similar manner to other shells when the POSIX_BUILTINS option is enabled.
Ignored-signal traps are now inherited by subshells when the POSIX_TRAPS option is enabled.
emulate sh: Inf and NaN are now treated as parameter names in arithmetic context when zsh is emulating sh.
The ${name:offset:length} expansion syntax now behaves more similarly to other shells in that the offset and length are applied as array indices prior to scalar conversion in e.g. "${*:0:2}".
The optimization for the =(<<<foo) construct with no command, which creates a temporary file with contents "foo", now adds a newline byte after "foo" for consistency with the behaviour of the <<< redirection everywhere else.
Incompatibilities between 5.7.1 and 5.8.1
The history expansion !:1:t2 used to be interpreted such that the 2 was a separate character added after the history expansion. Now it is an argument to the :t modifier.
For example
% echo /my/interesting/path % echo !:1:t2
used to echo "path2", but now echoes "interesting/path".
The behaviour of :h has similarly changed.
The behaviour has also changed in forms
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
