im building a small bash script project.My code getting 2 arguments, one path to search and one number that tells me how many folders level i have to analyze. For Example if the user gives the number 2 my programm it must search all directories within it and all directories within them.
#!/bin/bash
function check_dir {
echo Checking dir : $1
for f in `ls $1`
do
if [ -d $1/$f ]
then
dirs_num=$(($dirs_num+1))
check_dir $1/$f
else
files_num=$(($files_num+1))
size=`stat -c%s $1/$f`
echo $1/$f - $size
fi
done
}
files_num=0
dirs_num=0
depth=$2
check_dir $1
echo "Found $files_num files and $dirs_num dirs."
This is my code so far, im giving the path when i execute it but it gives me result for any folder that it finds.So how can i stop this loop? Thank you.