写一个脚本实现不同分支下的代码sync
递归去检索某个文件下的所有文件
#!/bin/bash
#usage:
#source sync_code.sh (源码路径) (目标路径)
SOURCEDIR=$1
TARGETDIR=$2
if [ ! -d $SOURCEDIR ] || [ ! -d $TARGETDIR ] ; then
echo "Input path is not exist!"
fi
function is_ready(){
sou_dir=$1
tar_dir=$2
if [ ! -d $sou_dir ] || [ ! -d $tar_dir ] ; then
echo "The paths do not exist or the two do not match!"
else
#该方法不完全可取 因为文件夹下存在make.inc
#cd $sou_dir
#cp -fp `ls |grep -v data|xargs`
#cd $tar_dir
#find -name *.inc |xargs rm -rf
if ls $sou_dir/*.h >/dev/null 2>&1;then
#echo "this path exit target_file *.h"
cp -fp $sou_dir/*.h $tar_dir/
else
echo "this path does not exit target_file *.h"
fi
if ls $sou_dir/*.c >/dev/null 2>&1;then
#echo "this path exit target_file *.c"
cp -fp $sou_dir/*.c $tar_dir/
else
echo "this path does not exit target_file *.c"
fi
#可以手动添加其他格式的文件
fi
}
function cp_file(){
sou_dir=$1
tar_dir=`echo ${sou_dir} |sed "s?${SOURCEDIR}?${TARGETDIR}?g"`
echo $tar_dir
echo $sou_dir
is_ready $sou_dir $tar_dir
}
function dir_list(){
for file in $1
do
if [ -d "$file" ]
then
cp_file $file
dir_list $file"/*"
fi
done
}
dir_list $SOURCEDIR