Makefile 变量操作 [英] Makefile variable manipulation

查看:40
本文介绍了Makefile 变量操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在这样做:

apply: init
    @terraform apply -auto-approve
    BUCKET=$(shell terraform output -json | jq '.S3_Bucket.value')
    DYNAMODB=$(shell terraform output -json | jq '.dynamo_db_lock.value')
    @echo $${BUCKET}

make 显示两个变量都被设置(我使用 := 但这对我不起作用,因为我在执行 apply 时需要设置它们)但它仍然回显空白:

make shows both variables being set (I was using := but that doesn't work for me, since i need them set when i execute apply) but it's still echoing blank:

...
Outputs:

S3_Bucket = "bucket1"
dynamo_db_lock = "dyna1"
BUCKET="bucket"
DYNAMODB="dyna1"
    <-- echo should print it out here

我想在之后将该变量用于 sed...

I want to use that variable for a sed afterwards...

谢谢大家!

推荐答案

每个 makefile 配方行都在自己的 shell 中运行.因此,在一个配方行中设置的 shell 变量不会影响其他配方行.您可以通过按如下方式连接所有行来解决此问题:

Each makefile recipe line is run in its own shell. Thus, shell variables set in one recipe line will not effect other recipe lines. You can get around this by catenating all the lines as so:

 apply: init
    @terraform apply -auto-approve
    @BUCKET=$(shell terraform output -json | jq '.S3_Bucket.value'); \
     DYNAMODB=$(shell terraform output -json | jq '.dynamo_db_lock.value'); \
     echo $${BUCKET}

这篇关于Makefile 变量操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆