Here’s a script that will help you count the lines of input from the standard input:
result=0 while read inputline do result=`expr $result + 1` done echo $result
Now, you can find out the number of files in a directory using:
ls -1 | count
Update
As Jeff Harver has kindly pointed out in the comments, the same thing as the long script above can be accomplished using:
ls | wc -l
For what it’s worth, you can also use wc -l.
ls | wc -l
Interesting. I never knew that there was a `-l` argument.