bash Makefile while 循环

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4355383/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 23:02:38  来源:igfitidea点击:

Makefile while loop

templatesbashmakefilewhile-loop

提问by dav

Even after setting SHELL to bash instead of sh, the following does not work:

即使将 SHELL 设置为 bash 而不是 sh,以下操作也不起作用:

doc:
    while read line; do \
      eval echo "$$line" > $(DOC) \
    done < $(DOC).templ

/bin/bash: -c: line 3: syntax error: unexpected end of file

What I'm trying to do is have a template file with bash parameter comprehensions and such ($(), ${}) and "build" it at compile time. Is there a better way to do this?

我想要做的是有一个模板文件,其中包含 bash 参数理解等 ( $(), ${}) 并在编译时“构建”它。有一个更好的方法吗?

回答by hlovdal

You are missing a semicolon before done:

您在完成之前缺少分号:

doc:
    while read line; do \
      eval echo "$$line" > $(DOC); \
    done < $(DOC).templ

回答by daniel kullmann

This answer might come to late ;-), but I think another problem is that your output redirection is in the wrong position:

这个答案可能来晚了;-),但我认为另一个问题是您的输出重定向位置错误:

doc:
    while read line; do \
      eval echo "$$line"; \
    done < $(DOC).templ > $(DOC)