Getting error “xargs unterminated quote” when tried to print the number of lines in terminal

后端 未结 4 1169
情书的邮戳
情书的邮戳 2021-01-31 02:57

I want to get the number of lines in my application. I am using this code:

find . \"(\" -name \"*.m\" -or -name \"*.h\" \")\" -print | xargs wc -l
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 03:34

    Does one of your filenames have a quote in it? Try something like this:

    find . "(" -name "*.m" -or -name "*.h" ")" -print0 | xargs -0 wc -l
    

    The -print0 argument tells find to use the NULL character to terminate each name that it prints out. The -0 argument tells xargs that its input tokens are NULL-terminated. This avoids issues with characters that otherwise would be treated as special, like quotes.

提交回复
热议问题