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 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
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With