---
title: "一个简单的脚本，利用数组、函数和for"
author: "jackchen0227"
date: "2013-03-22T16:04:00Z"
tags: []
categories: ["编程语言"]
slug: "for"
draft: false
lastmod: "2013-03-22T16:04:00Z"
id: 1834916
url: "https://jackchen0227.iteye.com/blog/1834916"
---

```
#!/bin/bash
svnUrl=( #数组
     url1
     url2
     )
    
targetDir=~/odp/app/groupon

buildModule()
{         
     echo $2
     svn co $2 temp
     cd temp
    
     find ./ -name .svn -exec rm -rf {} \;
     if [ -d  actions ];
     then
          echo actions
          cp actions $1/ -r
     fi

     if [ -d  models ];
     then
          echo models
          cp models $1/ -r
     fi

     if [ -d  library ];
     then
          echo library
          cp library $1/ -r
     fi

     if [ -d  script ];
     then
          echo script
          cp script $1/ -r
     fi

     if [ -d  controllers ];
     then
          echo controllers
          cp controllers $1/ -r
     fi    
    
     #cd ..
     #rm temp -rf
}

if [ ! -d $targetDir ];
then
     echo "make app root dir"
     mkdir $targetDir -p
fi

for i in ${svnUrl[*]} #数组遍历
do
     echo $i
     buildModule $targetDir, $i
done
```