Created
August 23, 2023 22:58
-
-
Save eugrus/1406fcc8ba86482e6329e90e2304dd98 to your computer and use it in GitHub Desktop.
Bash/CGI parsing of URI args separated by whitespaces
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 | |
echo "Content-Type: text/plain; charset=utf-8" && echo | |
IFS='?' read -ra url_parts <<< "$REQUEST_URI" | |
# Extract the query string from the URL | |
query_string="${url_parts[1]}" | |
# URL-decode the query string | |
decoded_query_string=$(printf '%b' "${query_string//%/\\x}") | |
# Split the decoded query string into an array using space as delimiter | |
IFS=' ' read -ra query_params <<< "$decoded_query_string" | |
# Debug: | |
#echo "First element: ${query_params[0]}" | |
#echo "Second element: ${query_params[1]}" | |
#echo "Third element: ${query_params[2]}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment