此代码是用来回忆当初学的shell脚本,很多知识忘了,写这个花了我三个小时的时间
#!/bin/ksh
#count *.c file the num of lineg_csum=0g_hsum=0
count(){# echo "$1,count_line" file_name="$1" res_line=`wc -l $file_name | awk '{PRint $1}'` echo $res_line return# find . -name "*.c" | xargs cat | wc -l}
statistics(){ echo "program start running" cur_line=0 echo $1# g_sum=`count $1` if test -f $1
then cur_line=`count $1` if [ "${1##*.}" = "c" ] then g_csum=$(($g_csum+$cur_line)) elif [ "${1##*.}" = "h" ] then g_hsum=$(($g_hsum+$cur_line)) fi echo $cur_line elif [ -d $1 ] then for file in $1/* do statistics $file done fi echo "g_csum" $g_csum echo "g_hsum" $g_hsum}
for file in $1
do statistics $1done
exit 0
新闻热点
疑难解答