Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使下面的代码返回以空格分隔的单词数?
example='aaa bbb ccc ddd eee' echo ${#example}
该命令echo ${#example}返回字母总数 (19)。返回总字数(5)的最佳命令是什么?
echo ${#example}
$ foo=($example) $ echo ${#foo[*]} 5
如果您想在没有变量的情况下执行此操作
$ set $example $ echo $# 5
尝试使用wc代表的命令word count
wc
word count
wc -w <<< "$example" wc -w <<< "asdf asdf asdf"