${(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 是一款支持 w** 的 **Zsh 集成开发环境 - 立即试用
© 2020–2024 Joachim Ansorg
声明
隐私政策
许可条款