这是我的第一个输入(记录为 bash var $services)
{
"key": "movies-wikibase-jobrunner",
"subPath": "LocalSettings.php",
"cm": "movies-wikibase-jobrunner-localsettings-override-php"
}
{
"key": "movies-wikibase-wdqs-frontend",
"subPath": "wdqs_front_index.html",
"cm": "movies-wikibase-wdqs-frontend-index-html"
}
我想使用subPath来更新deployment.json。 我尝试将 subPath 作为 bash 参数传递给 jq 但没有任何效果
cat deployment.json | jq -r --arg services $services '((.spec.template.spec.containers[].volumeMounts[]? )) |= {mountPath: .mountPath, name: (.key, subPath: $services|select(.key=="movies-wikibase-wdqs-frontend").subPath})'
我怎样才能实现这一目标,这是好方法吗?
jq --argjson services "$services" '
.spec.template.spec.containers[].volumeMounts[] |=
(
.name as $name |
. + { mountPath: ($services[] | select(.key == $name).subPath // .mountPath) }
)
' deployment.json > updated_deployment.json