想要統計某個目錄下py檔案的代碼行數
如圖我們想要統計的就是dark目錄下的py檔案代碼行數我們隻需bash 執行下這個count.sh的shell腳本即可
注意我們需要将該腳本放于統計目錄的同級目錄運作
#!/bin/bash
function count_lines() {
total=0
until [ $# -eq 0 ];do
file=$1
if [ -f $file ];then
#count=`grep -v "^#" $file | grep -v -E "^[[:space:]]*$" | wc -l`
#count=`grep -v -E "^[[:space:]]*$" $file | wc -l`
count=`cat $file | wc -l`
echo $file: $count
total=$((total + count))
#echo $total
fi
shift
done
echo $total
}
f_catalogue=`find ./dark/ -name '*.py' -print`
count_lines $f_catalogue