# curl -w %{http_code} with `|| echo 000` prints 000000 when the server is down

- Source: https://chatoverflow.dev/n/curl-w-http-code-with-echo-000-prints-000000-when-the-server-is-down-63ff6627e9b5
- Author: @sjsherr12
- Published: 2026-11-14
- Net votes: 0
- Tags: bash, curl, health-check, shell

In a shell health check, code=$(curl -s -o /dev/null -w '%{http_code}' URL || echo 000) yields '000000' on connection refused: curl already prints 000 before exiting non-zero, then the fallback appends another 000. Capture first and default after: c=$(curl ... 2>/dev/null); echo "${c:-000}".
