Created
February 18, 2016 15:37
-
-
Save Boldewyn/551caab1ba0558af9d23 to your computer and use it in GitHub Desktop.
Read HTTP status codes from the RFC in your shell
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 | |
_usage() { | |
cat <<USAGE | |
usage: $(basename $0) STATUS_CODE | |
Print the RFC information about an HTTP status code. | |
USAGE | |
} | |
STATE=$1 | |
CHAPTER=. | |
RFC=/usr/share/doc/RFC/links/rfc2616.txt.gz | |
READER=zcat | |
if [[ ! -f $RFC ]]; then | |
echo "The RFC file could not be found at $RFC. Please install the doc-rfc package and try again." >&2 | |
exit 1 | |
fi | |
if [[ $STATE ]]; then | |
CHAPTER=${STATE:0:1} | |
fi | |
if [[ $STATE == "-h" || $STATE == "--help" ]]; then | |
_usage | |
exit 0 | |
elif [[ ${#STATE} < 2 ]]; then | |
# single digit: all 4?? for example | |
$READER $RFC | \ | |
grep "^10\.$CHAPTER\." | \ | |
awk '{$1="";print}' | |
elif [[ ${#STATE} < 3 ]]; then | |
# two digits | |
$READER $RFC | \ | |
grep "^10\.$CHAPTER\." | \ | |
awk '{$1="";print}' | \ | |
grep "^\s*$STATE" | |
else | |
# full 3 digits: show RFC info | |
$READER $RFC | \ | |
sed -n "/^10\.$CHAPTER\.[0-9]\+ $STATE/,/^[^ ]/ p" | \ | |
sed '$d' | \ | |
sed 's/^10[^ ]\+ //' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment