Skip to content

Instantly share code, notes, and snippets.

@timmc
Last active November 16, 2022 03:23
Show Gist options
  • Select an option

  • Save timmc/1524e73039238ea4a94c106f8f71f90f to your computer and use it in GitHub Desktop.

Select an option

Save timmc/1524e73039238ea4a94c106f8f71f90f to your computer and use it in GitHub Desktop.
Get HTTP status code and body in separate variables using curl
#!/bin/bash
all_out="$(curl -sS https://www.spidersge.org/ -w '%{http_code}')"
status="$(echo "$all_out" | tail -c4)"
echo "Status is [$status]"
body="$(echo "$all_out" | head -c-4)"
echo "Body is [$body]"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment