Date: Thu, 07 Jan 2010 22:47:24 +0100 From: "Bernard T. Higonnet" <bth@higonnet.net> To: freebsd-questions@freebsd.org Subject: Can't figure out recursion problem in bash/freebsd Message-ID: <4B46566C.4050705@higonnet.net>
index | next in thread | raw e-mail
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
home |
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B46566C.4050705>
