[SWLUG] shell script help

Robert McQueen robot101 at debian.org
Sun Oct 20 23:08:34 UTC 2002


On Sun, Oct 20, 2002 at 11:18:50PM +0100, bascule wrote:
> i need to enter each subdirectory of a higher level directory, perform the 
> same command and then back out and in to any other sub directories
> is using:
> 
> for i in`ls -R`;
> 	do yadayada;
> done
> 
> an appropriate way to do this or is there a better way?
> 
> bascule

It's appropriate in principle, it will just fail to work. Try:

dir=`pwd`
for i in `find . -type d`; do
  cd $dir/$i
  whatever
done
cd $dir

Unless your 'whatever' command can take a directory as an argument, in
which case you could do:

find . -type f -exec whatever {} \;

Regards,
Rob




More information about the Swlug mailing list