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
echo $mystring | wc -w
or
echo $mystring | wc --words
will do a word count for you.
You can pipe each word to wc:
echo $token | wc -m
to store the result in a variable:
mycount=`echo $token | wc -m`
echo $mycount
to add to the total as you go word by word, do math with this syntax:
total=0
#start of your loop
total=$((total+mycount))
#end of your loop
echo $total