将jq查询字符串分成几行 [英] Break jq query string into lines
本文介绍了将jq查询字符串分成几行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我放置"\"查询中断时,如何将jq字符串分成几行,这适用于长行.
How can i break jq string into lines, this is for long lines, when i put "\" query breaks.
vpcExists=$(aws ec2 describe-vpcs --profile $profile | jq -r --arg vpcId "$vpcId" '.[][] | \
select(.VpcId == $vpcId) \
| .["State"]' \
)
推荐答案
jq
可以使用文字换行符,因此只需在任意位置添加换行符即可,而不必尝试转义它们:
jq
is fine with literal line breaks, so just add linefeeds anywhere without trying to escape them:
vpcExists=$(aws ec2 describe-vpcs --profile $profile |
jq -r --arg vpcId "$vpcId" '
.[][]
| select(.VpcId == $vpcId)
| .["State"]'
)
这是MCVE:
jq -r --arg vpcId "someId" '
.[][]
| select(.VpcId == $vpcId)
| .["State"]' << 'EOF'
{ "Vpcs": [ {
"VpcId": "someId",
"InstanceTenancy": "default",
"State": "available",
"IsDefault": false
} ] }
EOF
这篇关于将jq查询字符串分成几行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文