0%

shell批量文件内容复制到一个文件内

公司需要把所有代码放到一个文件内,加上版权信息. 于是用shell简单的处理了下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/sh

NAME="a.txt"
if [ -f $NAME ]; then
`rm $NAME`
fi

DIR=""
FILE=""
for file in `ls -R`
do
if [ -f $file ]; then
if [ $file = "a.sh" ];then
continue
fi
# echo "===================== $file begin =====================" >> $NAME
# `cat $file >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $file
else
if [ ${file:0:1} = "." ];then
DIR=${file/://}
else
if [ "$DIR" != "" ] && [ ${DIR:0:6} = "./base" ];then
continue #此处可以过滤不想要的文件夹
fi
FILE=$DIR$file
if [ -f $FILE ]; then
# echo "===================== $file begin =====================" >> $NAME
# `cat $FILE >> $NAME`
# echo "===================== $file end =====================" >> $NAME
echo $FILE
fi
fi
fi
done
给作者打赏,可以加首页微信,咨询作者相关问题!