bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how could I execute a set of script in a directoy tree?


From: Mike Stroyan
Subject: Re: how could I execute a set of script in a directoy tree?
Date: Wed, 14 Nov 2007 00:51:59 -0700
User-agent: Mutt/1.5.15+20070412 (2007-04-11)

On Wed, Nov 14, 2007 at 01:38:01PM +0800, 龙海涛 wrote:
...
> but now what i want to do is write a shell script , call all the
> autotest.sh in every leaf-directory.

  You could do that with a recursive function that descends into
each directory.  Using ( ) around the cd to a subdirectory will
return to the previous directory at the closing parenthesis.
Looking for autotest.sh files in just leaf directories would be
harder than executing those files in all directories of the tree.
It would be possible to test for the presence of subdirectories
first and suppress execution of autotest.sh in non-leaf directories.
But I will assume that you don't actually require that.

r () 
{ 
    cd "$1"
    if [ -x autotest.sh ]; then
        ./autotest.sh;
    fi;
    for d in *
    do
        if [ -d "$d" ]; then
            ( r "$d" )
        fi;
    done
}

Then run
  r /testcase
to acutally use the recursive function on /testcase.

But the find command is very good at doing this as well.

 find /testcase -name autotest.sh -perm /111 -execdir bash -c ./autotest.sh \;

-- 
Mike Stroyan <mike@stroyan.net>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]