Shell脚本 SVN导出两个版本差异文件

Shell/Python   svn差异版本  
#!/bin/bash
#导出指定版本之间的差异文件 如100到200之间的差异则导出100(不包括)-200(包括)的所有修改
SVN_URL="svn://192.168.1.23/svn/repotest"

if [ -z $2 ] && [ $1 -gt $2 ] ; then  
        echo "You must useage like $0 old_version1(不包括) new_version(包括)"
        exit 1
fi

OLD_VERSION=$1  
NEW_VERSION=$2

WORK_PATH=`pwd`"/version_patch/${OLD_VERSION}_${NEW_VERSION}"

echo "开始分析版本差异..."  
DIFF_URL="svn diff -r ${OLD_VERSION}:${NEW_VERSION} --summarize --username leoiceo --password 123456 ${SVN_URL}"  
echo ${DIFF_URL}

if test ! -e "${WORK_PATH}"; then  
        mkdir -p ${WORK_PATH}
fi  
echo ${DIFF_URL}|sh >${WORK_PATH}_diff.txt

DIFF_NUM=`${DIFF_URL} |wc -l`  
if [ ${DIFF_NUM} -ne 0 ]; then  
        echo "差异文件共${DIFF_NUM}个,准备导出."
        DIFF_LIST=`${DIFF_URL}`
        #echo ${DIFF_LIST}
        NUM=0
        SKIP=0
        for FIELD in ${DIFF_LIST} ; do
                #长度小于3(A、M、D、AM即增加且修改)即是更新标识,否则为url
                if [ ${#FIELD} -lt 3 ]; then
                        let NUM+=1
                        SKIP=0
                        if [ "${FIELD}" == "D" ]; then
                                #下一个应该跳过
                                SKIP=1
                        fi
                        continue
                fi

                #若为删除文件则不必导出
                if [ ${SKIP} -eq 1 ]; then
                        echo ${NUM}.'是删除操作,跳过:'${FIELD}
                        continue
                fi

                #替换得到相对路径
                DIFF_FILE=${FIELD//${SVN_URL}/}
                echo ${NUM}.' '${DIFF_FILE}

                FILE_NAME=`basename ${DIFF_FILE}`
                FOLDER_NAME=`dirname ${DIFF_FILE}`
                FOLDER_PATH="${WORK_PATH}${FOLDER_NAME}"
                #echo ${FILE_NAME}' '${FOLDER_NAME}' '${FOLDER_PATH}

                if test ! -e "${FOLDER_PATH}"; then
                        mkdir -p ${FOLDER_PATH}
                fi

                CMD="svn export -r ${NEW_VERSION} ${SVN_URL}${DIFF_FILE} ${FOLDER_PATH}/${FILE_NAME}"
                #echo ${CMD}
                #echo ${NUM}.' '
                echo ${CMD}|sh
        done
        echo "完成"
else  
        echo "版本间没有差异"
fi