考慮包含(僅)由所得到的3個文件的目錄:如何在makefile中轉義雙美元?
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
到目前爲止,一切都很好。現在,這個指令生成文件,例如:
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。
可能是相關的:http://stackoverflow.com/questions/1320226/four-dollar-signs-in-makefile – Frodon
通過將$ $$加倍,可以在makefile配方中轉義'$'。參見[在食譜中使用變量](http://www.gnu.org/software/make/manual/make.html#Variables-in-Recipes)。 –
[如何在makefile中引用perl $符號]可能的重複(http://stackoverflow.com/questions/13691180/how-to-quote-a-perl-symbol-in-a-makefile) – tripleee