#!/bin/bash -
#===============================================================================
#
# FILE: count.sh
#
# USAGE: ./count.sh
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: Karl Zheng (http://blog.csdn.net/zhengkarl)
# COMPANY: Meizu
# CREATED: 2010年10月12日 17时18分59秒 CST
# REVISION: ---
#===============================================================================
set -o nounset # Treat unset variables as an error
suffix=( '*.c' '*.h' '*.cpp' '*.cxx' '*.hpp' '*.hxx' '*.java' '*.xml' 'Makefile' 'kconfig' '*.mk' )
command_str=" "
i=0
while [ $i -lt ${#suffix[@]} ];do
if [ $i -eq 0 ];then
command_str="$command_str"" -iname /"${suffix[$i]}/" "
else
command_str="$command_str"" -o -iname /"${suffix[$i]}/" "
fi
((i++))
done
line_sum="0"
for f in $(echo "$command_str" |xargs find );do
line_nr=$(wc -l $f)
line_sum=$(echo $line_sum $line_nr |awk '{print $1+$2}')
done
echo "total line:"$line_sum