For Make循环中没有任何效果 [英] For loop in Makefile has no effect
问题描述
我将一行脚本传递到Makefile中的 foreach
函数中,如下所示:
<$ $ {code $>(foreach f,$ * .txt,printf%s\\\
0a$(grep -o'[0-9] \ + '$ f | sed's /.*/ read \& \/')。wq | ed $ f)
这个脚本行的功能可以找到此处。我只是感到困惑,为什么它不能这样工作,因为如果我把这行放到一个单独的脚本中并像这样从Makefile中调用它:
标志:
$(forech f,$ * .txt,./script $ f)
它工作正常。
我也尝试了循环的shell ,如下所示:
标志:
代表$ *中的f。txt;做\
printf%s\\\
0a$(grep -o'[0-9] \ +'$ f | sed's /.*/ read \& \ /')。 w q | ed $ f; \
完成
仍然没有运气。我必须触及Makefiles的一些微妙点,任何人都可以启发我吗?感谢。
解决方法是:在序列以 grep
,
标志:
$( foreach f,$ * .txt,printf%s\\\
0a$$(grep -o'[0-9] \ +'$ f | sed's /.*/ read \& \/')。wq | ed $ f)
或者使用旧的反引号而不是
标志:
$(foreach f,$ * .txt,printf%s\\\
0a `grep -o'[0-9] \ +'$ f | sed's /.*/ read \& \/'`。wq | ed $ f)
I have a one-line script passed into the foreach
function in a Makefile, as shown below:
flag:
$(foreach f, $*.txt, printf "%s\n" 0a "$(grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/')" "" . w q | ed $f)
What this script line does could be found here. I am just puzzled why it doesn't work this way, because if I put the line into a separate script and call it from the Makefile like this:
flag:
$(forech f, $*.txt, ./script $f)
it works fine.
I also tried the shell for
loop as follows:
flag:
for f in $*.txt ; do \
printf "%s\n" 0a "$(grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/')" "" . w q | ed $f ; \
done
still no luck. I must touch some subtle points of Makefiles, could anyone enlighten me? Thanks.
The solution is: adding one more $
before the sequence beginning with grep
,
flag:
$(foreach f, $*.txt, printf "%s\n" 0a "$$(grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/')" "" . w q | ed $f)
or use the old backticks instead
flag:
$(foreach f, $*.txt, printf "%s\n" 0a "`grep -o '[0-9]\+' $f | sed 's/.*/read \"&\"/'`" "" . w q | ed $f)
这篇关于For Make循环中没有任何效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!