管道在makefile中不起作用

Ell*_*nce 3 bash grep makefile

我已经拉出了重要的线条:

SHELL := /bin/bash

leaks: build_eagle_test
    grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print $1' | sort | uniq > leaks.alloc.tmp
    grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print $1' | sort | uniq > leaks.alloc_test.tmp
Run Code Online (Sandbox Code Playgroud)

当我在bash中运行行没问题.但是从make文件中它只管理grep到out文件中(实际上忽略了两者之间的阶段......)

and*_*otn 9

$需求被表示成$$,例如,

SHELL := /bin/bash

leaks:
    grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print $$1' | sort | uniq > leaks.alloc.tmp
    grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print $$1' | sort | uniq > leaks.alloc_test.tmp
Run Code Online (Sandbox Code Playgroud)

问题是Make对bash语法一无所知,忽略'"了命令行上的所有引用.它在Make上下文中解释$1变量的值1- 但是没有这样的变量,因此它变成空白.

当它从原始Makefile回显它运行的命令时,你可以在Make的输出中看到这个:

$ make
grep EagleMemory_Allocate -r eagle | perl -nle 'm/"(.*)"/; print ' | sort | uniq > leaks.alloc.tmp
grep "EagleMemory_Mock(" -r eagle_test | perl -nle 'm/"(.*)"/; print ' | sort | uniq > leaks.alloc_test.tmp
Run Code Online (Sandbox Code Playgroud)

注意$1已经消失了.