我有这个 JSON 对象,它将补丁集的兼容性映射到特定的软件版本。
{
"compatibility":{
"v7.11.x":[
"7.12.1",
"7.12.0",
"7.11.2",
"7.11.1",
"7.11.0"
],
"v7.13.x":[
"7.14.2",
"7.14.1",
"7.14.0",
"7.13.1",
"7.13.0"
],
"v7.15.x":[
"8.1.0",
"8.0.1",
"8.0.0",
"7.17.1",
"7.17.0",
"7.16.1",
"7.16.0",
"7.15.1",
"7.15.0"
]
}
}
Run Code Online (Sandbox Code Playgroud)
当给定特定版本(例如“8.1.0”)时,是否可以jq返回补丁集名称(例如“v7.15.x”)?
是的,实际上非常简单。
.compatibility | to_entries[] | select(.value | index("8.1.0")) .key
Run Code Online (Sandbox Code Playgroud)
如果不清楚,版本字符串不必进行硬编码;它也可能来自程序外部:
.compatibility | to_entries[] | select(.value | index("8.1.0")) .key
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
214 次 |
| 最近记录: |