make函数如何在makefile中运行的Bash循环内工作

问题描述 投票:1回答:2

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

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

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

bash makefile gnu-make
2个回答
1
投票

这是make内部的解决方案:

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

[在结束;之前请注意),该命令用于分隔echo命令,因为它们将在外壳的一行中执行。如果shell命令比简单的echo更复杂,那么最好使用成熟的canned recipe


0
投票

您的for由外壳执行,并且$(subst ...)是make函数,因此将在外壳有机会循环之前执行。您必须在shell中获得等效功能。例如

Part=hey high huh
Str=hey do not be high huh
entity:
        @for n in $(Part) ; do \
            echo $$(echo $(Str) | sed "s/$$n//") ; \
        done
© www.soinside.com 2019 - 2024. All rights reserved.