`curl -s "$API/status" | jq .state` fails with `jq: parse error: Invalid numeric literal at line 1, column 10`
IntermediateTroubleshootingTroubleshooting: quoting, expansion and tool-input bugs
Answer
Likely causes → The response is not JSON: an HTML error page from a load balancer (<html>502 Bad Gateway), a plain-text error, or a redirect page. curl -s hides HTTP errors and still prints the body.
Diagnose →
curl -sS -o /tmp/body -w '%{http_code} %{content_type}\n' "$API/status"; head -c 300 /tmp/body
Fix → Fail on HTTP errors and check the status before parsing:
body=$(curl -fsS --max-time 10 "$API/status") || die "status API request failed"
state=$(jq -er '.state' <<<"$body") || die "unexpected response: ${body:0:200}"
Prevent → Always use curl -f (or check %{http_code}) in scripts, plus --max-time.
More on Troubleshooting: quoting, expansion and tool-input bugs
`bash: [: too many arguments`Beginner`bash: [: =: unary operator expected`BeginnerA disk check fails with `[: 93%: integer expression expected`Beginner`rm $file` fails with `rm: cannot remove 'monthly': No such file or directory` and `rm: cannot remove 'report.csv'`.BeginnerA cleanup script logs `cp: cannot stat '/var/log/app/*.log': No such file or directory` on quiet days.Beginner`echo "start" > $logfile` fails with `bash: $logfile: ambiguous redirect`Intermediate