Skip to content

Instantly share code, notes, and snippets.

@zmarffy
Last active October 25, 2021 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zmarffy/7eebf20535ce9b642ad5cdfb4ecb20b4 to your computer and use it in GitHub Desktop.
Save zmarffy/7eebf20535ce9b642ad5cdfb4ecb20b4 to your computer and use it in GitHub Desktop.
Get an HTTP response as well as the HTTP status code when using `curl`
out=$(curl "http://httpbin.org/get?key=value" -w "%{http_code}\\n" -sS)
sc=$(echo "$out" | tail -n -1)
json=$(echo "$out" | sed \$d)
echo -e "STATUS CODE:\n$sc\n\nJSON:\n$json"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment