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 <[EMAIL PROTECTED]>


Reply via email to