Skip to content

Instantly share code, notes, and snippets.

@joshenders
Created May 31, 2013 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshenders/5683369 to your computer and use it in GitHub Desktop.
Save joshenders/5683369 to your computer and use it in GitHub Desktop.
$QUERY_STRING parser
#!/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