Counting characters, words, length of the words and total length in a sentence

后端 未结 7 1907
别跟我提以往
别跟我提以往 2021-02-20 15:08

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

7条回答
  •  孤独总比滥情好
    2021-02-20 15:35

    string="i am a string"
    
    n=$(echo $string | wc -w )
    
    echo $n
    
    4
    

    The value of n can be used as an integer in expressions

    eg.
    
    echo $((n+1))
    5
    

提交回复
热议问题