Skip to content

Instantly share code, notes, and snippets.

@cicorias
Created February 6, 2019 21:45
Show Gist options
  • Select an option

  • Save cicorias/1121c6d9f170d4de1984172b9da1db56 to your computer and use it in GitHub Desktop.

Select an option

Save cicorias/1121c6d9f170d4de1984172b9da1db56 to your computer and use it in GitHub Desktop.
curl and capture both stdout and http status
#creates a new file descriptor 3 that redirects to 1 (STDOUT)
exec 3>&1
# Run curl in a separate command, capturing output of -w "%{http_code}" into HTTP_STATUS
# and sending the content to this command's STDOUT with -o >(cat >&3)
HTTP_STATUS=$(curl -w "%{http_code}" -o >(cat >&3) 'http://example.com')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment