【发布时间】:2018-08-28 17:12:37
【问题描述】:
我在自己的小 shell 中执行了“grep”。 其他命令,如 'ls -al'、'pwd' ..etc,正在工作。 但是当我输入 'grep' 时,出现了一些问题。
char* f_grep[] = {"grep", "-n", "a", "a.txt", NULL};
char* s_grep[] = {"grep", "-n", "'a'", "a.txt", NULL};
execvp(f_grep[0], f_grep); // This works.
execvp(s_grep[0], s_grep); // This doesn't work.
我想知道为什么我不能在 execvp() 中对 grep 使用引号。
谢谢。
【问题讨论】:
-
“不起作用”是什么意思?它工作得很好——它找到了三个字符的字符串
'a',就像它应该做的那样。 -
@CharlesDuffy 谢谢!!现在我可以理解我做错了什么。非常感谢。
标签: c shell grep execvp quotation-marks