我在 Emacs 中遇到了 greps 问题。
a) grep 似乎不理解用于搜索 .c 和 .h 文件的 .[ch]。这是 Emacs 使用lgrep命令提供的默认选项。该示例在 .c/.h 文件中搜索单词“global”。
grep -i -nH "global" *.[ch]
grep: *.[ch]: No such file or directory
Grep exited abnormally with code 2 at Mon Feb 16 19:34:36
这种格式无效吗?
b)使用rgrep我得到以下错误:
find . "(" -path "*/CVS" -o -path "*/.svn" -o -path "*/{arch}" -o -path "*/.hg" -o -path "*/_darcs" -o -path "*/.git" -o -path "*/.bzr" ")" -prune -o -type f "(" -iname "*.[ch]" ")" -print0 | xargs -0 -e grep -i -nH "global"
FIND: Wrong parameter format
Grep finished (matches found) at Mon Feb 16 19:37:10
我在 Windows XP 上使用 Emacs 22.3.1 和 GNU W32 Utils(grep、find、xargs 等)。grep v2.5.3 并找到 v4.2.20。
我错过了什么?
更新:
太糟糕了,不能接受多个答案......因为我的问题的解决方案已经展开。
grep -i -nH "global" *.c *.h
这解决了第一个问题。谢谢luapyad!
(setq find-program "c:\\path\\to\\gnuw32\\find.exe")
emacs 确实在使用 Windows find.exe。强制 gnu32 find 解决了第二个问题。谢谢斯科特弗雷泽。
不过,我还是最喜欢ack。