首页 > 解决方案 > make 函数如何在 makefile 中运行的 Bash 循环中工作

问题描述

make 函数如何在 Bash 循环中工作,尝试过:

Part=hey high huh
Str=hey do not be high huh
entity:
    @for n in $(Part) ;{ \
      echo $(subst $$n,,$(Str)); \
    }

删除某些字符串..不起作用,如何解决?

标签: bashmakefilegnu-make

解决方案


这是make内部的一个解决方案:

Part=hey high huh
Str=hey do not be high huh
entity:
    $(foreach p,$(Part),echo $(filter-out $(p),$(Str));)

请注意;关闭之前)用于分隔命令的echo命令,因为它们将在 shell 的一行中执行。如果 shell 命令变得比简单的命令更复杂echo,您最好使用成熟的罐头食谱


推荐阅读