初衷:
在兄弟目录下寻找类似目录树并将目录树拷过来合并到自己的目录树下
## cp --parent `find 纯源码/ -name "*.[ch]"` 工程框架壳/
set -a sourcefilelist
line=0
for f in `find 纯源码/ -name "src"`
do
sourcefilelist[$line]="$f"
((line++))
done
set -a targetfilelist
line=0
for f in `find 工程框架壳/ -name "src"`
do
targetfilelist[$line]="$f"
((line++))
done
for (( i=0;i<line;i++ ))
do
source=${sourcefilelist[$i]}
target=${targetfilelist[$i]}
echo "复制 $source 到 $target "
cp -a $source $target/../
done
echo "复制 纯源码/mc/lib 工程框架壳/mc/lib"
cp -a 纯源码/mc/lib 工程框架壳/mc/
echo "复制 纯源码/lib 工程框架壳/lib"
cp -a 纯源码/lib 工程框架壳/
echo "复制 纯源码/mmc/src 工程框架壳/mmc/src"
cp -a 纯源码/mmc/src 工程框架壳/mmc/
date=`date +%Y%m%d`
echo "已经重命名 “工程框架壳” 为 combineCode-S1-$date , 请将其拷出,推送仓库时切勿连同此文件夹推入"
chmod 644 ./工程框架壳
mv ./工程框架壳 combineCode-S1-$date
检出一倍push到git仓库
function dosomething ()
{
if [ -d NewsourceCOde ]
then
echo "当前目录下已经有NewsourceCOde,此操作可能导致原有文件被覆盖,是否覆盖,是请按y/Y"
read yn
if [ $yn != "Y" ] && [ $yn != "y" ]
then
echo "你已选择中途退出"
exit
fi
rm -rf NewsourceCOde
fi
mkdir NewsourceCOde
line=0
for f in `find 纯源码/ -name "src"`
do
sourceDir[$line]="${f#*/}"
echo "拷贝 $1/${sourceDir[$line]} 到 NewsourceCOde/ 并保留目录层次"
cp -a --parent $1/${sourceDir[$line]} NewsourceCOde/
((line++))
done
for f in `find 纯源码/ -name "lib"`
do
libfile="${f#*/}"
echo "拷贝 $1/$libfile 到 NewsourceCOde/ 并保留目录层次"
cp -a --parent $1/$libfile NewsourceCOde/
done
mv NewsourceCOde/$1/* NewsourceCOde/
dirstr=$1
if [ ${dirstr:0:1} == "/" ]
then
dirstr=${dirstr#*/}
fi
rm -rf NewsourceCOde/${dirstr%%/*}
rm -rf 纯源码
mv NewsourceCOde 纯源码
}
if [ $# != 1 ]
then
echo "请在命令后面附带要提取源码的路径"
echo "例如: ./getPushCode /d/ccsv7code/combineCode-S1-20190111"
exit
fi
if [ ! -d $1 ]
then
echo "路径不存在,请检查斜杠是否用反了"
echo "正确示范: ./getPushCode /d/ccsv7code/combineCode-S1-20190111"
exit
fi
echo "你确定从 $1 提取.c .h文件吗? Y/N [Y]"
read yn
if [ $yn == "Y" ] || [ $yn == "y" ]
then
dosomething $1
else
echo "你没有选择目录, 请在询问时输入Y或y"
exit
fi