shelllings

a practical way to learn shell
git clone https://git.davidvoz.net/shelllings.git
index
logs
tree
license

07_wordcount.sh
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#
12file="LICENSE"
13word_count=$(wc -w $file)
14line_count= # fix this
15byte_count= # fix this
16
17echo "$line_count"
18echo "$word_count"
19echo "$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.