[英]Interpolate variable in command substitution in Makefile
I am trying to do variable interpolation inside a command substitution in a Makefile. 我正在尝试在Makefile中的命令替换内进行变量插值。
I have this code: 我有以下代码:
setup:
mkdir -p data_all ; \
for i in $(shell jq -r 'keys | @tsv' assets.json) ; do \
git_url=$(shell jq -r ".$$i" assets.json) ; \
git clone $$git_url data_all/$$i ; \
done
The code is failing, however, because $$i
does not expand in the "shell" line that sets git_url. 但是,代码失败,因为$$i
不会在设置git_url的“ shell”行中扩展。
How do I interpolate the variable $i in the "shell" line that sets git_url? 如何在设置git_url的“ shell”行中插入变量$ i?
You mixed up make functions ( $(shell ...)
) and true shell constructs. 您将make函数( $(shell ...)
)和真正的shell构造混合在一起。 When writing a recipe the simplest is to write it first in plain shell: 编写配方时,最简单的方法是先在普通外壳中编写:
mkdir -p data_all ; \
for i in $( jq -r 'keys | @tsv' assets.json ) ; do \
git_url=$( jq -r ".$i" assets.json ) ; \
git clone $git_url data_all/$i ; \
done
And then escaping the unwanted $
expansion by make: 然后通过make转义不必要的$
扩展名:
mkdir -p data_all ; \
for i in $$( jq -r 'keys | @tsv' assets.json ) ; do \
git_url=$$( jq -r ".$$i" assets.json ) ; \
git clone $$git_url data_all/$$i ; \
done
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.