command set

Hello
I'm using command "set" to count number of word in file .
But I don't know how to get number of lines in file using commnad "set " ?.
Please Help.


#!/bin/sh
set -- `cat $1`
echo " $# words "     # wc -w $1

any reasons why set? you can count lines in number of ways, using sed, wc ,awk etc
here's an eg

awk 'END{print NR}' file
grep -c '' file

you can use wc (word count)

count=`wc -w file_name`

echo $count

You could modify IFS to include the newline character or:

contents=`cat file`
set -- $contents
echo $#

Just for information, and I do no think this is the case here. I can think of a number of places where knowing how to use set instead of other tools is important:

For example in an init script. In single user mode on a system with a separate /usr the other "standard" tool will not be available.