带有 grep 的 xargs 传递一个空字符串
xargs with grep passes an empty string
当我使用 xargs 将文件名传递给 grep 时,grep: : No such file or directory
来自哪里?
⋊> ~/.v/bundle find . -name config | grep ".git" | xargs grep "url" {} 11:07:46
grep: : No such file or directory
./Dockerfile.vim/.git/config: url = https://github.com/ekalinin/Dockerfile.vim.git
./nerdcommenter/.git/config: url = https://github.com/scrooloose/nerdcommenter.git
虽然我这样做时没有空行或类似的东西
⋊> ~/.v/bundle find . -name config | grep ".git" 11:08:30
./Dockerfile.vim/.git/config
./nerdcommenter/.git/config
以及如何避免呢?
我知道我可以跳过第一行 awk 'NR>1'
但我想了解问题的原因。
谢谢。
P.S。我在 Mac.
不需要添加{}
(不像find -exec
)
~/.v/bundle find . -name config | grep ".git" | xargs grep "url"
应该可以。
甚至更好(以防文件名或目录名包含空格或不寻常的字符):
~/.v/bundle find . -name config -print0 | grep -z ".git" | xargs --null grep "url"
很难说您的网站出了什么问题。我试图重现错误,也有 .vim/bundle
,但我无法重现它。
无论如何,我建议将命令简化为:
find . -wholename '*/.git/config' -exec grep -H url {} +
xargs
不再需要,因为 find
支持 +
语法。这至少适用于 find
.
的 GNU、BSD (MacOS) 和 busybox 版本
当我使用 xargs 将文件名传递给 grep 时,grep: : No such file or directory
来自哪里?
⋊> ~/.v/bundle find . -name config | grep ".git" | xargs grep "url" {} 11:07:46
grep: : No such file or directory
./Dockerfile.vim/.git/config: url = https://github.com/ekalinin/Dockerfile.vim.git
./nerdcommenter/.git/config: url = https://github.com/scrooloose/nerdcommenter.git
虽然我这样做时没有空行或类似的东西
⋊> ~/.v/bundle find . -name config | grep ".git" 11:08:30
./Dockerfile.vim/.git/config
./nerdcommenter/.git/config
以及如何避免呢?
我知道我可以跳过第一行 awk 'NR>1'
但我想了解问题的原因。
谢谢。
P.S。我在 Mac.
不需要添加{}
(不像find -exec
)
~/.v/bundle find . -name config | grep ".git" | xargs grep "url"
应该可以。
甚至更好(以防文件名或目录名包含空格或不寻常的字符):
~/.v/bundle find . -name config -print0 | grep -z ".git" | xargs --null grep "url"
很难说您的网站出了什么问题。我试图重现错误,也有 .vim/bundle
,但我无法重现它。
无论如何,我建议将命令简化为:
find . -wholename '*/.git/config' -exec grep -H url {} +
xargs
不再需要,因为 find
支持 +
语法。这至少适用于 find
.