简体   繁体   English

如何遍历 makefile 中的字符串?

[英]How do I loop through a string in makefile?

I want to write a Makefile that will iterate through a string and print it word by word.我想写一个 Makefile 将遍历一个字符串并逐字打印。

Here is what I did in the Makefile:这是我在 Makefile 中所做的:

MINION="fou foo bar"
test:
    @for n in $(MINION); do \
        echo "$$n"; \
    done

Actual output:实际 output:

fou foo bar

What I want to get is:我想要得到的是:

fou
foo
bar

I also want to iterate on sentences that has a whitespace and coma separator, ex.我还想迭代具有空格和逗号分隔符的句子,例如。 "fou, foo, bar" “呸,呸,酒吧”

Makefile variables do not use the same assignment syntax as shell variables. Makefile 变量不使用与 shell 变量相同的赋值语法。 MINION="foo fou bar" will assign the string "foo fou bar" to the MINION Makefile variable, which will then be substituted into the shell command line as for n in "foo fou bar" . MINION="foo fou bar"会将字符串"foo fou bar" fou bar" 分配给MINION Makefile 变量,然后将其替换到 shell 命令行中,如for n in "foo fou bar"

Use instead改为使用

MINION = foo fou bar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM