Created
May 31, 2013 07:14
-
-
Save joshenders/5683369 to your computer and use it in GitHub Desktop.
$QUERY_STRING parser
This file contains hidden or 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 | |
if [[ -z "$QUERY_STRING" ]]; then | |
# default if $QUERY_STRING is empty | |
QUERY_STRING="crust=thin&name=jenders&topping=cheese" | |
fi | |
crust="$(tr '&' '\n' <<< $QUERY_STRING | awk -F= '/crust/ { print $2 }')" | |
name="$(tr '&' '\n' <<< $QUERY_STRING | awk -F= '/name/ { print $2 }')" | |
topping="$(tr '&' '\n' <<< $QUERY_STRING | awk -F= '/topping/ { print $2 }')" | |
printf "Content-Type: text/html\r\n\r\n" | |
cat << EOF | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>CGI Demo</title> | |
</head> | |
<body> | |
<span>Hello $name, I see you like $crust crust $topping pizza. A fine choice!</span> | |
</body> | |
</html> | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment