Re: Can't figure out recursion problem in bash/freebsd - reply/solution to all helpers

2010-01-08 Thread Bernard T. Higonnet

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
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org


Can't figure out recursion problem in bash/freebsd

2010-01-07 Thread Bernard T. Higonnet

Dear freebsd list,

There must be something simple I'm getting wrong in attempting a simple 
recursive bash script.


I want to do something on every file in a tree, so I have a script which 
recurses when it finds a directory and processes the file when it is not 
a directory.


My testbed is a directory with 3 subdirectories and a few files. My 
script correctly recognizes the first directory encountered, recurses to 
process that sub-directory, but when it comes back it no longer 
recognizes the next item as a directory, though it is indeed a 
directory. In the script given below, the processing of an actual file 
is represented by echo processing $hoo.


If I eliminate the recursion but enter and then exit the sub-directory 
(i.e. I replace line $0 with cd ..) the sub-directories are 
correctly recognized.




echo starting in `pwd`
for hoo in *
  do
echo $hoo
if [ -d $hoo ]
  then echo pushing $hoo; cd $hoo
  $0
  else echo processing $hoo
fi;
  echo going to next item
  done
cd ..


I have tried various minor variations , all to no avail.

I have no doubt I'm doing something very dumb, but I'm too locked into 
my vision to see it...


All help appreciated
Bernard Higonnet
___
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to freebsd-questions-unsubscr...@freebsd.org