${(Z:opts)…}: Splitting with shell parsing and opts

(Z:opts:) is like (z) but takes additional settings to configure the parsing process. Without any options ((Z::)) works in exactly the same way as (z). It’s possible specify more than option, e.g. ${(Z:Cn:)name}.

It splits the expansion into words using shell parsing, i.e. as if the expansion was entered as a command.

The splitting is performed after other flags are applied. Use nesting to work with the resulting words of (Z:opts:).

Options

c
Causes comments to be parsed and retained
C
Causes comments to be parsed and removed
n
Causes unquoted newlines to be treated as ordinary whitespace and not as command separators

Examples

Split string using shell parsing and drop comments
1
2
3
4
5
string="# simple embedded shell script
echo -n hello
echo world"
# split using shell parsing and drop the comment line
echo ${(Z:C:)string}
Output:
1
; echo -n hello ; echo world
BashSupport Pro ist eine Zsh IDE mit Unterstützung für ${(Z)…} - probieren Sie es jetzt aus!
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches