Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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
如何在makefile中逃逸双美元?_Makefile_Grep_Escaping_Dollar Sign - Fatal编程技术网

如何在makefile中逃逸双美元?

如何在makefile中逃逸双美元?,makefile,grep,escaping,dollar-sign,Makefile,Grep,Escaping,Dollar Sign,考虑一个目录,该目录包含(仅)通过以下方式获得的3个文件: echo "foobar" > test1.txt echo "\$foobar" > test2.txt echo "\$\$foobar" > test3.txt (因此分别包含foobar,$foobar,$$foobar) grep指令: grep -l -r --include "*.txt" "\\$\\$" . 过滤包含双美元的文件(实际上是唯一文件): $ grep -l -r --include

考虑一个目录,该目录包含(仅)通过以下方式获得的3个文件:

echo "foobar" > test1.txt
echo "\$foobar" > test2.txt
echo "\$\$foobar" > test3.txt
(因此分别包含
foobar
$foobar
$$foobar

grep
指令:

grep -l -r --include "*.txt" "\\$\\$" .
过滤包含双美元的文件(实际上是唯一文件):

$ grep -l -r --include "*.txt" "\\$\\$" .
./test3.txt
到目前为止,一切顺利。现在,此指令在makefile中失败,例如:

doubledollars:
    echo "Here are files containing double dollars:";\
    grep -l -r --include "*.txt" "\\$\\$" . ;\
    printf "\n";\
导致错误的原因:

$ make doubledollars
echo "Here are files containing double dollars:";\
grep -l -r --include "*.txt" "\\\ . ;\
printf "\n";\

/bin/sh: -c: ligne 2: unexpected EOF while looking for matching `"'
/bin/sh: -c: ligne 3: syntax error: unexpected end of file
makefile:2: recipe for target 'doubledollars' failed
make: *** [doubledollars] Error 1
因此我的问题是:如何在makefile中逃逸双美元


编辑:请注意,这个问题不涉及Perl。

使用以下
Makefile

a:
  echo '$$$$'
制作一个

$$
。。。如果不需要变量展开,最好使用单引号:

grep -l -r -F --include *.txt '$$' .

当然,除非您编写的脚本能够在MinGW环境中的Windows上执行。

可能相关:您可以通过将makefile配方中的
$
加倍来转义它。请参阅。但是
grep-l-r的可能重复项--包括“*.txt”$$$$”。
(使用单引号并将每个美元加倍)不支持makefile中用于筛选包含双美元的文件的作业。美元符号是
grep
中的元字符,因此需要反斜杠转义或包含在字符类中。试试
grep…“\$\$$”
grep….'[$$][$$].
其中仍然需要双美元符号才能使其脱离Make。很抱歉,您必须省略单引号,这样通配符才能工作。更正了答案。@tripleee,或使用grep-F