Recursive shell scripts

William Setzer IDM setzer at nssdcs
Sat Jul 1 04:16:12 AEST 1989


I am trying to use the Bourne shell to write recursive shell scripts.
The problem is that I can't get the positional parameters to pass
correctly.  Here is what I've written.

--------------
#!/bin/sh
export PATH
cd ${1:-`pwd`}
for I in `ls`
do
if test -d $I; then
   . $0 $I;
else
  echo `pwd`'/'$I
fi
done
-------------

According to what the man page says, this should work, but it doesn't.
For some reason or another, the $I parameter isn't being passed back into
the program (I always get the same value for $1).  I know they can be
passed; I wrote a script that did it.  My best guess is that somehow it finds
itself linked in memory and decided to link to the already running process.
I tried putting parens around '. $0 $I' to run it in it's own subshell, but
that didn't work either.  I'm stumped.  Can anyone help me?  Thanx.
Oh yeah, I'm running SunOS 4.0 (it's really BSD 4.?).

William Setzer
setzer at nssdcs.gsfc.nasa.gov



More information about the Comp.unix.questions mailing list