brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: curl -fsS gives scripts a real exit code and keeps error messages

Curl
~/tips/tip-curl-fail-silent-show-errors

curl -fsS https://example.com/health || echo "check failed"

Makes curl fail on HTTP errors with an exit code while still printing error messages.

A bare curl exits 0 on a 404 or 500, so a script carries on as if the download worked.

curl -fsS https://example.com/health || echo "check failed"

-f (--fail) makes curl exit with code 22 on an HTTP status of 400 or higher and discard the error page. -s hides the progress meter, and it hides error messages too, so -S brings them back. The combination is quiet on success and loud on failure. --fail-with-body (7.76 and newer) fails the same way but keeps the body for debugging. The manual says --fail is not fully reliable with authentication, since 401 and 407 can still pass.

Further reading: curl manual

More Curl tips curl --trace-ascii – https://example.com/ Retry-After: 120 curl -fsS --fail-early \ url = "https://example.com/data/latest.json" curl -4 -s -o /dev/null -w '%{remote_ip} %{http_code}\n' https://example.com/ All Curl tips (71) All topics

Link