curl -w / --write-out: Capture Status and Timings
-w lets you read the status code and timings without parsing headers.
When you need to branch on the HTTP status or measure latency, -w exposes the numbers directly.
What it does
-w / --write-out <format> prints text after the transfer completes, expanding %{variable} tokens. Common variables are %{http_code} (the status), %{time_total}, %{time_namelookup}, %{size_download}, and %{url_effective}. It writes to stdout, so combine it with -o to separate the body from the status. You can also read the format from a file with @file.
Common usage
code=$(curl -s -o /dev/null -w '%{http_code}' https://api.example.com/health)
curl -s -o resp.json -w 'status=%{http_code} time=%{time_total}s\n' https://api.example.com/x
echo "status=$code" >> "$GITHUB_OUTPUT"Flags
| Variable / flag | What it does |
|---|---|
| %{http_code} | The HTTP status code of the final response |
| %{time_total} | Total transfer time in seconds |
| %{time_namelookup} | Time spent on DNS resolution |
| %{size_download} | Bytes downloaded |
| %{url_effective} | Final URL after redirects |
| -o /dev/null | Discard the body so -w stands alone |
In CI
To branch on a status, capture %{http_code} with -o /dev/null and test it in the shell, then write the result to $GITHUB_OUTPUT so later steps can read it. This is how you act on a 202-vs-200 distinction without a JSON parser. Use -w timings to flag slow dependencies.
Common errors in CI
Seeing the body mixed with your status means you forgot -o /dev/null (or -o file). A literal %{http_code} in output indicates the shell ate the braces; wrap the format in single quotes. Remember %{http_code} is the status, not an exit code.