##
# walk [ command args ] # General-purpose directory tree traversal thingy. # traverse the directory tree starting at cwd and do command in # each dir. Much slower than find, but much simpler to use, and # of course, to modify. # Also included in cLIeNUX as an example of recursion in sh. # Works in Bash and ash. walk () { local f top_args=$* for f in * { if test -d $f -a ! -L $f; then cd $f walk $top_args cd ../ fi } $top_args } walk $* # local has to be in a function, hence the "define and then call" # layout. Notice how $f is reentrant, and how top_args gets # passed inside, but executed outside the inner call. ## Copyright 2000 Rick Hohensee