${(w)…}: Word count

w used together with #name counts words in arrays or string

Flag (s) can be used to define the word delimiter.

(W) can be used instead if empty words should be counted, too.

Examples

Count words
1
2
3
4
string="string with several words"
array=(array "with several" words)
echo ${(w)#string}
echo ${(w)#array}
Output:
1
2
4
4
BashSupport Pro ist eine Zsh IDE mit Unterstützung für ${(w)…} - probieren Sie es jetzt aus!
© 2020–2024 Joachim Ansorg
Impressum
Datenschutz
Rechtliches