Home > other >  why is jq not working inside bash variable
why is jq not working inside bash variable

Time:02-02

I have the following code

#/bin/bash
set -e
set -x

requestResponse=$(ssh jump.gcp.xxxxxxx """source dev2 spi-dev
kubectl get pods -o json | jq '.items[] |select(.metadata.name[0:3]=="fea")'  | jq .status.podIP
2>&1""")
echo $requestResponse

In the above code source dev2 spi-dev means we have moved to spi-dev namespace inside dev2 cluster. kubectl get pods -o json | jq '.items[] |select(.metadata.name[0:3]=="fea")' | jq .status.podIP 2>&1""") means to print ip address of pod starting with fea. If I do manually kubectl command works. I have also tried escaping fea like \"fea\"

CodePudding user response:

These triple quotes """ are not working as you expect. Try to change it like this:

ssh jump.gcp.xxxxxxx << EOF
source dev2 spi-dev
kubectl get pods -o json             | \
jq '.items[]                         | \
select(.metadata.name[0:3]=="fea")'  | \
jq .status.podIP 2>&1
EOF
  •  Tags:  
  • Related