spi*_*man 4 variables json string-literals string-interpolation jq
test.sh不会替换test.json参数值($ input1和$ input2)。result.json具有相同的ParameterValue“ $ input1 / solution / $ input2.result”
[
{
"ParameterKey": "Project",
"ParameterValue": [ "$input1/solution/$input2.result" ]
}
]
Run Code Online (Sandbox Code Playgroud)
#!/bin/bash
input1="test1"
input2="test2"
echo $input1
echo $input2
cat test.json | jq 'map(if .ParameterKey == "Project" then . + {"ParameterValue" : "$input1/solution/$input2.result" } else . end )' > result.json
Run Code Online (Sandbox Code Playgroud)
jq脚本中的shell变量应通过以下命令插入或作为参数传递--arg name value:
jq --arg inp1 "$input1" --arg inp2 "$input2" \
'map(if .ParameterKey == "Project"
then . + {"ParameterValue" : ($inp1 + "/solution/" + $inp2 + ".result") }
else . end)' test.json
Run Code Online (Sandbox Code Playgroud)
输出:
[
{
"ParameterKey": "Project",
"ParameterValue": "test1/solution/test2.result"
}
]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1511 次 |
| 最近记录: |