Makefile中的$(shell ...)命令未正确执行,但在bash / sh中有效

时间:2013-12-24 08:37:20

标签: bash shell makefile

我想计算Makefile中graphviz文件中的节点数,以使用它为每个节点启动进程。 我跑的时候

grep -- -\> graph.gv | while read line; do for w in $line; do echo $w; done; done | grep [Aa-Zz] | sort | uniq | wc -l
在shell中,它按预期打印节点数。 但是,当我在Makefile中使用它时

NODES := $(shell grep -- -\> graph.gv | while read line; do for w in $line; do echo $w; done; done | grep [Aa-Zz] | sort | uniq | wc -l)

${NODES}始终为0.

1 个答案:

答案 0 :(得分:3)

你需要逃避$标志。说:

NODES := $(shell grep -- -\> graph.gv | while read line; do for w in $$line; do echo $$w; done; done | grep [Aa-Zz] | sort | uniq | wc -l)