Detect the final page of a paginated cURL response in a Bash loop Detect the final page of a paginated cURL response in a Bash loop curl curl

Detect the final page of a paginated cURL response in a Bash loop


Assuming my theory about startIndex holds water and implementing @CharlesDuffy's suggestion about jq, this becomes

for ((i=0; ; i+=100)); do    contents=$(curl -u "username:password" -H "Content-Type: application/json" "https://<url>/api/core/v3/places?count=100&startIndex=$i")    echo "$contents" > $i.json    if jq -e '.list | length == 0' >/dev/null; then        break    fi <<< "$contents"done