考虑一个包含(仅)通过以下方式获得的 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 '$$$$'
make a
给$$
...如果您不需要变量扩展,最好使用单引号:
grep -l -r -F --include *.txt '$$' .
除非您编写脚本以便能够在 MinGW 环境中的 Windows 上执行。
关于makefile - 如何在makefile中逃避双美元?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33873789/