【发布时间】:2015-04-09 09:32:30
【问题描述】:
我在 Makefile 的目标中运行以下命令。
target1:
<run some command which creates ids.log>
$(eval id1 := $(shell cat ids.log | head -1))
@echo id is $(id1)
<some other command which uses the value $(id1)>
我的任务是获取“ids.log”中的第一行并将其保存在变量 id1 中,这样我就可以在此目标中接下来执行的命令中使用该值。
运行此命令时出现错误“cat: ids.log: No such file or directory”。看起来 $(eval .. ) 命令在 make 开始时执行,而不是作为目标 make 的一部分。而且由于在目标 make 完成之前不会创建 ids.log,因此我们会收到此错误。
谁能帮助我获取我执行的 shell 命令的值并将其放入变量中以供按需使用?
【问题讨论】: