test1.txt echo "\$foobar" > test2.txt echo "\$\$foobar"-6ren">
gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 15:20:34 24 4
gpt4 key购买 nike

考虑一个包含(仅)通过以下方式获得的 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com