Makefile:如何将对象分配给变量并迭代数组的对象

Makefile:如何将对象分配给变量并迭代数组的对象

生成文件:

QUERY := "securityresources | where type == 'microsoft.security/assessments' | summarize by assessmentKey=name | join kind=inner ( securityresources | where type == 'microsoft.security/assessments/subassessments' | extend assessmentKey = extract('.*assessments/(.+?)/.*',1, id) ) on assessmentKey | where properties.additionalData.assessedResourceType == 'ContainerRegistryVulnerability' | extend status = properties.status.code | extend severity = properties.status.severity"

.ONESHELL:
check:
    # az graph query -q ${QUERY}
    results="`az graph query -q ${QUERY}`"
    @for result in $$results.data;
    do
        echo "$${result.status}"
    done

的输出az graph query -q ${QUERY}看起来像:

{ "count": 10,
  "data" : [{"status":"healthy", "abc":"123"},
            {"status":"unhealthy", "abc":"322"},
            {"status":"healthy", "abc":"432"}
           ]
}

错误:

/bin/bash: 第 4 行: ${result.status}: 错误替换 make: ***

[Makefile:23: 检查] 错误 1

如何将命令输出分配给变量并迭代该对象以及访问这些对象的键、值?

答案1

您可以使用jq它来迭代 JSON。

就像是:

az graph query -q ${QUERY} | jq .data[].status

虽然不确定这与make

相关内容