#!/bin/bash
#
# Counts the files in this directory (and sub directories) or
# in the passed directory (and its sub directories).

# Param present?
if [ $# -ne 0 ]; then
    cd $1
fi

recursive_count() {
    count=0;
    for d in *; do
	if [ -d "$d" ]; then
	    tmp=$(cd -- "$d" && recursive_count)
	    count=$((count+tmp))
	else
	    count=$((count+1))
	fi 
    done
    echo $count
}

recursive_count 

