Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
unix中的搜索字符串_Unix_Command_Find - Fatal编程技术网

unix中的搜索字符串

unix中的搜索字符串,unix,command,find,Unix,Command,Find,我想显示包含字符串CHAR*getenv的所有文件名,其中getenv是一个函数。 我正在使用这个查询 find . -type f -exec grep -l "CHAR * getenv" {} \; 但它并没有给出期望的输出。它使用字符串CHAR getenv而不是CHAR*getenv显示文件名。使用grep-F防止搜索字符串被视为正则表达式 find . -type f -exec grep -lF "CHAR * getenv" {} \; 或 您需要对*进行转义,因为它意味着0

我想显示包含字符串CHAR*getenv的所有文件名,其中getenv是一个函数。 我正在使用这个查询

find . -type f -exec grep -l "CHAR * getenv" {} \;

但它并没有给出期望的输出。它使用字符串CHAR getenv而不是CHAR*getenv显示文件名。

使用grep-F防止搜索字符串被视为正则表达式

find . -type f -exec grep -lF "CHAR * getenv" {} \;


您需要对*进行转义,因为它意味着0个或多个正在进行的字符(在本例中是空格)

问题是bash扩展发生在grep命令执行之前:因此您的行被转换为
find-类型f-exec grep-l CHAR smt getenv{}\;找到-类型f-exec grep-l CHAR smt2 getenv{}\
用单引号替换双引号应该可以解决这个问题,因为这样bash扩展就不会发生

find . -type f -exec grep -l "CHAR \* getenv" {} \;
grep -rl "CHAR \* getenv" *