REcursive fuction call in shell script problem
This is shell script I have made to lists out directory contents and filenames for any given directory (without using ls command). There is some problem in dirfunc function call which I have marked 1 is not working. Can anybody suggest what is the problem there and how should I correct it.
dirfunc()
{ path=$1/$2
if test -d $path
then
echo "--------------------------------------------------------------------------------"
dir=Sub-$3
echo " $dir: $path "
dir $path > inven
declare -a no
awk 'BEGIN{ t = 0}
{ { for(i=1 ; i<=NF ; i++)
{
no[t+$i] = $i
dirfunc $path no[t+$i] $dir _____________________(1)not working
}
t = t + NF
}
}' inven
echo "--------------------------------------------------------------------------------"
else
if test -f $path
then
echo " $2 : File in $dir "
fi
fi
}
dirfunc /users/mti2007/apakhale/Desktop demodir.d Directory
To the best of my knowledge, shell scripts do not provide local variables by default, only global variables. This makes all subroutines non-reentrant and thus recursive calls do not work.
On the other hand, I have to wonder why you're reinventing find.
On the other hand, I have to wonder why you're reinventing find.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement