Counting characters, words, length of the words and total length in a sentence
问题 I have to write a script that takes a sentence and prints the word count, character count (excluding the spaces), length of each word and the length. I know that there exist wc -m to counter number of characters in the word, but how to make use of it in script? #!/bin/bash mystring="one two three test five" maxlen=0; for token in $mystring; do echo -n "$token: "; echo -n $token | wc -m; if [ ${#token} -gt $maxlen ]; then maxlen=${#token}; fi; done echo "--------------------------"; echo -n