简单代码统计脚本

#!/bin/bash

#参数校验
if [ $# -ne 1 ]; then
	echo -e "\033[40;31;1mplease input your filename!\033[0m"
	exit 1
elif [ ! -f $1 ]; then
	echo -e "\033[40;31;1mfile:$1 doesn't exist!\033[0m"
	exit 1
fi

file_name=$1

#总行数
all_num=`sed -n "$"= $file_name`
#注释行数
note_num=`egrep "(^[[:space:]]*/\*)|([[:space:]]*//)" $file_name | wc -l`
#空行数
null_num=`grep "^[[:space:]]*$"  $file_name | wc -l`

echo 总行数: $all_num
echo 代码行: $((all_num - note_num - null_num))
echo 注释行: $note_num
echo 空 行:  $null_num

 

你可能感兴趣的:(shell编程)