REcursive fuction call in shell script problem

Started by
1 comment, last by kru 15 years, 2 months ago
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
Advertisement
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.
Local variables can be declared with the keyword local

This topic is closed to new replies.

Advertisement