2 linux gnu makefile gnu-make go
我有用 golang 实现的命令行工具,工作正常。我想执行一些应该提供字符串列表的命令
apps := $(shell fxt run apps)
apps:
@echo $(apps) is called
Run Code Online (Sandbox Code Playgroud)
在终端中,我在执行时看到以下内容make(完全没问题)
[app1 app2] is called
Run Code Online (Sandbox Code Playgroud)
由于命令fxt run apps返回字符串数组 ( var apps []string)
我的问题是我怎么能遍历的apps
变量?
命令返回的数据很好,但现在我需要获取这个列表(app1...appN)并循环它,我不清楚这个问题,我如何循环遍历字符串数组?
特殊情况是如果在循环列表中我app7应该如何在代码中做一个叉子,例如 if(app7) 打印mvn clean install
例子。
对于每个应用程序(在应用程序列表中)我需要运行命令
go test ./...
但是对于需要运行的app7
mvn clean install
和 app10
yarn
您想在 make 本身或实际上正在执行 shell 的配方中运行您的循环?在这里,你有两个!
备注:我将执行的命令替换为自己测试。在这里我ls用来填充我的数组。
apps := $(shell ls)
#looping in make itself
$(foreach var,$(apps),$(info In the loop running with make: $(var)))
#loop in shell inside recipe
go:
@for v in $(apps) ; do \
echo inside recipe loop with sh command: $$v ; \
done
Run Code Online (Sandbox Code Playgroud)
输出:
In the loop running with make: a
In the loop running with make: b
In the loop running with make: c
In the loop running with make: Makefile
inside recipe loop with sh command: a
inside recipe loop with sh command: b
inside recipe loop with sh command: c
inside recipe loop with sh command: Makefile
Run Code Online (Sandbox Code Playgroud)