如何在makefile中逃避双倍美元?

Den*_*uzé 0 grep makefile escaping dollar-sign

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

echo "foobar" > test1.txt
echo "\$foobar" > test2.txt
echo "\$\$foobar" > test3.txt
Run Code Online (Sandbox Code Playgroud)

(并且因此分别含有foobar,$foobar,$$foobar).

grep指令:

grep -l -r --include "*.txt" "\\$\\$" .
Run Code Online (Sandbox Code Playgroud)

过滤包含双倍美元的文件(实际上是唯一文件):

$ grep -l -r --include "*.txt" "\\$\\$" .
./test3.txt
Run Code Online (Sandbox Code Playgroud)

到现在为止还挺好.现在,该指令在makefile中失败,例如:

doubledollars:
    echo "Here are files containing double dollars:";\
    grep -l -r --include "*.txt" "\\$\\$" . ;\
    printf "\n";\
Run Code Online (Sandbox Code Playgroud)

导致错误:

$ 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
Run Code Online (Sandbox Code Playgroud)

因此我的问题是:如何在makefile中逃避双倍美元?

编辑:请注意,此问题不涉及Perl.

And*_*sev 5

以下 Makefile

a:
  echo '$$$$'
Run Code Online (Sandbox Code Playgroud)

make a

$$
Run Code Online (Sandbox Code Playgroud)

...如果您不需要变量扩展,最好使用单引号:

grep -l -r -F --include *.txt '$$' .
Run Code Online (Sandbox Code Playgroud)

除非您编写脚本以便能够在MinGW环境中的Windows上执行,原因.