REcursive fuction call in shell script problem

This topic is 3578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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

Share on other sites
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.

Share on other sites
Local variables can be declared with the keyword local

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• Forum Statistics

• Total Topics
633298
• Total Posts
3011256
• Who's Online (See full list)

There are no registered users currently online

×