count words in bash without wc 发布者:phpor 2018 年 7 月 16 日2018 年 7 月 16 日 于count words in bash without wc留下评论 如何计算字符串中单词的数量,但是不使用wc? eg: str="apple orange pear" arr=( $str ) echo ${#arr[@]} 123 str="apple orange pear"arr=( $str )echo ${#arr[@]} 如果字符串的内容在文件中,则可以直接 read -a arr 来读入到指定数组中,然后再获取数组的长度即可 参考: https://stackoverflow.com/questions/15108229/how-to-count-number-of-words-from-string-using-shell