Break jq query string into lines

后端 未结 1 850
渐次进展
渐次进展 2021-01-17 10:30

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 --         


        
相关标签:
1条回答
  • 2021-01-17 10:37

    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"]' 
    )
    

    Here's a MCVE:

    jq -r --arg vpcId "someId" '
       .[][] 
         | select(.VpcId == $vpcId)
         | .["State"]'  << 'EOF'
    
    
    { "Vpcs": [ {
                "VpcId": "someId",
                "InstanceTenancy": "default",
                "State": "available",
                "IsDefault": false
            } ] }
    EOF
    
    0 讨论(0)
提交回复
热议问题