脚本使用find来计算代码行数

chi*_*uba 1 bash

我正在尝试创建一个shell脚本,它将计算一个文件夹中的代码行数.

我懂了:

h=find . -type f -name \*.[h]* -print0 | xargs -0 cat | wc -l
m=find . -type f -name \*.[m]* -print0 | xargs -0 cat | wc -l

expr $m + $h
Run Code Online (Sandbox Code Playgroud)

但是当我试图运行它时,我得到了这个:

lines-of-code: line 6: .: -t: invalid option
.: usage: . filename [arguments]
   0
lines-of-code: line 7: .: -t: invalid option
.: usage: . filename [arguments]
   0
+
Run Code Online (Sandbox Code Playgroud)

我知道我必须做一些事情让它在我所在的特定文件夹上运行.这甚至可能吗?

Fre*_*ihl 6

DDIYS(不要自己动手)改用cloc.用perl编写的优秀工具,为您和其他事物计数.它识别80多种语言.

示例输出:

prompt> cloc perl-5.10.0.tar.gz
    4076 text files.
    3883 unique files.                                          
    1521 files ignored.

http://cloc.sourceforge.net v 1.50  T=12.0 s (209.2 files/s, 70472.1 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
Perl                          2052         110356         130018         292281
C                              135          18718          22862         140483
C/C++ Header                   147           7650          12093          44042
Bourne Shell                   116           3402           5789          36882
Lisp                             1            684           2242           7515
make                             7            498            473           2044
C++                             10            312            277           2000
XML                             26            231              0           1972
yacc                             2            128             97           1549
YAML                             2              2              0            489
DOS Batch                       11             85             50            322
HTML                             1             19              2             98
-------------------------------------------------------------------------------
SUM:                          2510         142085         173903         529677
-------------------------------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)