-
Notifications
You must be signed in to change notification settings - Fork 1
/
count_code_line.sh
executable file
·63 lines (57 loc) · 1.5 KB
/
count_code_line.sh
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/bash
#代码书行数统计脚本,只支持两级目录
all_count=0; #全部行数统计
file_count=0; #文件行数统计
filename="";
string="";
path=`pwd`;
for filename in `ls`;do
file_info=`ls -l | grep ${filename}`;
class=`echo ${file_info:0:1}`;
#目录
if [[ ${class} = 'd' ]];then
cd ${filename};
path=`pwd`;
for filename in `ls`; do
file_info=`ls -l | grep ${filename}`;
class=`echo ${file_info:0:1}`;
#第1级目录
if [[ ${class} = 'd' ]]; then
cd ${filename};
path=`pwd`;
for filename in `ls`; do
file_info=`ls -l | grep ${filename}`;
class=`echo ${file_info:0:1}`;
#第2级目录
if [[ ${class} = "d" ]]; then
#do nothing
echo "";
#第2级文件
else
string=`wc -l ${filename}`;
file_count=`echo ${string} |cut -d' ' -f 1`;
echo "line_count:${file_count} filename:${path}/${filename}";
let "all_count=file_count+all_count";
fi
done
cd ..;
path=`pwd`;
#第1级文件
else
string=`wc -l ${filename}`;
file_count=`echo ${string} |cut -d' ' -f 1`;
echo "line_count:${file_count} filename:${path}/${filename}";
let "all_count=file_count+all_count";
fi
done
cd ..;
path=`pwd`;
#文件
else
string=`wc -l ${filename}`;
file_count=`echo ${string} |cut -d' ' -f 1`;
echo "line_count:${file_count} filename:${path}/${filename}";
let "all_count=file_count+all_count";
fi
done
echo "total_line_count:${all_count}";