shelllings

a practical way to learn shell
Log | Files | Refs | README | LICENSE

07_wordcount.sh (772B)


      1 #!/bin/sh
      2 
      3 # wc, word count, is a program that measures and counts bytes, 
      4 # characters, and lines
      5 #
      6 # $ wc -l file      # counts the amount of lines in a file
      7 # $ wc -w file      # counts the amount of words in a file
      8 # $ wc -m file      # characters
      9 # $ wc -c file      # bytes
     10 # $ wc file         # gives out the lines, words, and bytes of a file
     11 #
     12 file="LICENSE"
     13 word_count=$(wc -w $file)
     14 line_count= # fix this
     15 byte_count= # fix this
     16 
     17 echo "$line_count"
     18 echo "$word_count"
     19 echo "$byte_count"
     20 
     21 # One more thing you should get used to is standard input. Run the wc 
     22 # command without an argument and it will take you to a new line. Type
     23 # whatever you want and end it with a ctrl d. You can run wc -w into
     24 # this environment as well to see the length of your sentence.