I am using a curl command to get json data from an application
the example curl response
{
"count": 2,
"value": [
{
"id": 344,
"name": "ip-172-20-94-68",
"status": "offline",
},
{
"id": 345,
"name": "ip-172-20-95-119",
"status": "offline",
}
]
}
My bash script
ipAddresses=$(curl -s -X GET "$hostUrl" -u :"$EncodedPAT" | jq -r ".value[] | select(.status==\"offline\").name")
ids=$(curl -s -X GET "$hostUrl" -u :"$EncodedPAT" | jq -r ".value[] | select(.status==\"offline\").id")
for ipAddress in "${ipAddresses[@]}"
do
for id in "${ids[@]}"
do
echo "ipAddress: ${ipAddress} id: ${id}"
done
done
output
ipAddress: ip-172-20-94-68
ip-172-20-95-119
ip-172-20-95-113
ip-172-20-94-96
ip-172-20-94-86
id: 344
345
346
348
350
So it looks like it is only iterating through the outermost loop once, and not iterating through the inner loops (just uses first element).
expected output
ipAddress: ip-172-20-94-68 id: 344
ipAddress: ip-172-20-95-119 id: 345
ipAddress: ip-172-20-95-113 id: 346
ipAddress: ip-172-20-94-96 id: 348
ipAddress: ip-172-20-94-86 id: 350
I've looked elsewhere on the net but am having trouble finding anything relevant.
Any guesses as to what might be wrong?