You just need to capture the depth value and reduce it by 1 each time you call
check_dir
. Something like:
function check_dir {
depth = $($2 - 1)
echo Checking dir : $1
for f in `ls $1`
do
if [ -d $1/$f ]
then
dirs_num=$(($dirs_num+1))
if [ $depth -gt 0 ]
then
check_dir $1/$f $depth
fi
else
files_num=$(($files_num+1))
size=`stat -c%s $1/$f`
echo $1/$f - $size
update_table $1/$f $size
fi
done
}
NB apologies if some of my syntax is wrong, it's a few years since I was writing shell scripts.