#!/bin/bash
#Program:
# Count every cpp file and h file is line in a path ,and add them ,output it
#History:
# Build by AstrayLinux in 2011/10/17
if [ $# -ge 1 ] ; then
i=0;
s=0;
t=0;
if [ -d $1 ] ; then
path=$1
shift
else
path="./"
fi
while [ "$i" != "$#" ]
do
str="\"*.$1\": "
echo "======================= *.$1 ========================="
find $path -type f -name "*.$1" -exec wc -l {} \;
t=`find $path -type f -name "*.$1" -exec cat {} \; |wc -l`
echo "====================== *.$1 SUM ======================"
printf "%11s %10d\n" $str $t
s=$(( $s+$t ))
shift
done
echo "===================== ALL SUM ======================="
printf "%11s %10d\n" "The all:" $s
else
echo ""
echo "countSrcLine [path] [filetype ...]"
echo " If path is empty ,it will be ./"
echo " Filetype is a postfix like cpp,log. etc."
echo " EXAMPLE: "
echo " countSrcLine ~/workspace/ cpp h"
echo ""
fi
exit 0
结果如下

本文介绍了一个bash脚本程序,用于统计指定路径下特定类型文件(如.cpp和.h文件)的总行数。该脚本可以处理多个文件类型,并在没有提供路径时默认搜索当前目录。
473

被折叠的 条评论
为什么被折叠?



