【问题标题】:How do I pass arguments that you are able to iterate through in a makefile?如何传递可以在 makefile 中迭代的参数?
【发布时间】:2021-10-14 07:38:33
【问题描述】:

我的 makefile 中有这个:

test_x_number_times:
for time in `seq $(TIMES)` ; do \
    for dc in $(DCs) ; do \
        echo $$dc ; \
            poetry run kit test -d $$dc --testcase-id=$(TESTCASES) || true ; \
    done ; \
done ;

并希望能够为TESTCASESDCs 传递多个值,以便我可以在for 循环中遍历它们,但我不知道如何在命令行中列出参数一种将值视为可以迭代的值的方式。这是我尝试过的:

  1. make test_x_number_times TIMES=1 DCs=B1,G1 TESTCASES=1,2
  2. make test_x_number_times TIMES=1 DCs=B1 G1 TESTCASES=1 2
  3. make test_x_number_times TIMES=1 DCs=(B1 G1) TESTCASES=(1 2)

我该怎么做?我在文档或 stackoverflow 的任何地方都找不到它。

【问题讨论】:

    标签: loops makefile command-line


    【解决方案1】:

    shell for 循环期望看到以空格分隔的单词进行迭代。要在单个 shell 参数中传递空格,您需要引用它:

    make make test_x_number_times TIMES=1 DCs='B1 G1' TESTCASES='1 2'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-08
      • 2013-08-04
      • 2023-03-19
      • 2021-02-26
      • 2011-04-28
      • 2017-03-31
      • 1970-01-01
      • 2017-01-17
      相关资源
      最近更新 更多