make函数如何在Bash循环内工作,尝试过:
Part=hey high huh
Str=hey do not be high huh
entity:
@for n in $(Part) ;{ \
echo $(subst $$n,,$(Str)); \
}
删除某些字符串..不起作用,如何解决?
这是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。
您的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