考虑一个仅包含3个文件的目录,这些文件是通过以下方式获得的:
导致错误:
因此,我的问题是:如何在makefile中转义双重美元符号? 编辑:请注意,这个问题不涉及Perl。
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。
$
加倍为$$
来转义。请参阅配方中使用变量。 - Etan Reisner