Last active
November 16, 2022 03:23
-
-
Save timmc/1524e73039238ea4a94c106f8f71f90f to your computer and use it in GitHub Desktop.
Get HTTP status code and body in separate variables using curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
all_output="$(curl -isS https://www.spidersge.org/)" | |
status=$(echo "$all_output" | grep -Po '\s[0-9]{3}\s' | head -n1 | tr -dc 0-9) | |
echo "Status is [$status]" | |
body="$(echo "$all_output" | sed -ne $'/^\r$/,$p' | tail -n+2)" | |
echo "Body is [$body]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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