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

标签 makefile grep escaping dollar-sign

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

相关文章:

c - 如何为visual studio构建工具cl.exe编写makefile(nmake)

git-grep 不使用多线程

c# - 使用@符号时如何在字符串中使用双引号?

linux - 如何在文件中搜索模式并在终端上显示该行?

linux - 优化从大数据集中提取文本

windows - 如何在PowerShell一线式中转义空间

regex - Bash 转义脚本和 sed 捕获组

c - gcc : warning: pf_xmit. o: 链接器输入文件未使用,因为链接未在 linux 中完成

创建一个更通用的 makefile

c++ - 从 Makefile 中的 C++FLAGS 中删除标志?