如何grep的工作? [英] How does grep work?
问题描述
我想了解如何的grep
的作品。
I am trying to understand how grep
works.
当我说的grep你好* *
,并的grep
得到2参数— (1)要搜索的字符串,即你好和(2)路径 *。*
?还是外壳转换 *。*
到的东西,的grep
能理解吗?
When I say grep "hello" *.*
, does grep
get 2 arguments — (1) string to be searched i.e. "hello" and (2) path *.*
? Or does the shell convert *.*
into something that grep
can understand?
我在哪里可以得到的grep
来源$ C $ C?我碰到这个 GNU 的grep
链接。其中的README文件中说,从其不同的UNIX的grep
。怎么会这样?
Where can I get source code of grep
? I came across this GNU grep
link. One of the README files says its different from unix grep
. How so?
我想看看在FreeBSD的版本的grep
,并且还Linux版本的它源(如果它们是不同的)。
I want to look at source of FreeBSD version of grep
and also Linux version of it (if they are different).
推荐答案
壳做的通配(从转换*
形式的文件名)。你可以看到这个,如果你有一个简单的C程序:
The shell does the globbing (conversion from *
form to filenames). You can see this by if you have a simple C program:
#include <stdio.h>
int main(int argc, char **argv) {
for(int i=1; i<argc; i++) {
printf("%s\n", argv[i]);
}
return 0;
}
然后运行它是这样的:
And then run it like this:
./print_args *
您会看到它打印出匹配的是什么,而不是 *
字面上。如果你调用它是这样的:
You'll see it prints out what matched, not *
literally. If you invoke it like this:
./print_args '*'
您会看到它得到一个文字 *
。
You'll see it gets a literal *
.
这篇关于如何grep的工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!