#!/bin/bash
export PATH=$PATH:/usr/bin
function countDir()
{
if [ $# -ne 1 ];then
echo "argv is $#"
return 0;
fi
local dirNumber=0
local fileNames=`ls $1`
local i
for i in $fileNames
do
local currentPath="$1/$i"
if [ -d $currentPath ];then
echo "$currentPath is dir"
countDir $currentPath
local newDirNum=$?
dirNumber=$(($dirNumber+$newDirNum+1))
fi
done
return $dirNumber
}
argv=$#
if [ $argv -ne 1 ];then
echo "$0 <count dir>"
exit -1;
fi
allNumber=0;
if [ -d "$1" ]; then
countDir $1
currDir=$?
allNumber=$(($allNumber+$currDir+1));
fi
echo "total Dir Number is ($allNumber)"