${(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.
Links
Examples
- Count words
- Output:
1 2 3 4
string="string with several words" array=(array "with several" words) echo ${(w)#string} echo ${(w)#array}
1 2
4 4
BashSupport Pro is a Zsh IDE with support for ${(w)…} – try it now!