Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 Jan 2010 11:23:33 +0100
From:      "Bernard T. Higonnet" <bth@higonnet.net>
To:        freebsd-questions@freebsd.org
Subject:   Re: Can't figure out recursion problem in bash/freebsd - reply/solution to all helpers
Message-ID:  <4B4707A5.2000009@higonnet.net>

next in thread | raw e-mail | index | archive | help
Hello,

There were two approaches offered to my problem

1) changing my script: it runs if the "cd .." is moved from the end of 
the script into the then clause of the if statement

===============
#! /bin/sh
echo Starting in `pwd`
for hoo in *; do
   echo Found item $hoo
   if [ -d "$hoo" ]; then
     echo Pushing $hoo
     cd $hoo
     $0
     cd ..
   else
     echo Processing file $hoo
   fi
   echo Going to next item
done
echo Finishing in `pwd`
# cd ..  was here in original script
===============

I shall be bold: this strikes me as a bug in bash. Am I off my nut here?



2) use find instead for the traversing of the file hierarchy

===============
find $PWD -type f -execdir processingscript {} \;
===============


I have tried both methods and on a small sample (10,000 files going only 
  3 deep) and there were no meaningful differences in execution time.

Thanks to all
Bernard Higonnet



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B4707A5.2000009>