Like cloc-work: Counting Lines Of Code Is An Easy Way To Get Information On Shell Scripts

Like cloc-work: Counting Lines Of Code Is An Easy Way To Get Information On Shell Scripts

It is sometimes useful to know how many lines of code your script is.  I enjoy using it as a reference to illustrate how writing a few lines of code can save you a lot of time that you would normally do manually.  I have always used

cat someScript.sh | wc -l

or

cat someScript.sh | grep -v "#" | wc -l

to find out how many lines my script was.

I was pleased to discover cloc  (counting lines of code), which is much better at displaying information about the script.

user@computer:~$ cloc someScript.sh

       1 text file.
       1 unique file.                              
       0 files ignored.

http://cloc.sourceforge.net v 1.62  T=0.01 s (89.9 files/s, 5841.1 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Bourne Shell                     1              7             13             45
-------------------------------------------------------------------------------

If you use Homebrew, it is very easy to get this little utility:

brew install cloc