Created
March 19, 2021 20:23
-
-
Save asolera/0b68431ae889a1b01e07605decf42a13 to your computer and use it in GitHub Desktop.
URL Encode with Shell Script
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
#!/usr/bin/env bash | |
# | |
# Credits to Meleu @ https://meleu.sh/urlencode/ | |
# Usage: urlencode "#" => will output "%23" | |
urlencode() { | |
local LC_ALL=C | |
local string="$*" | |
local length="${#string}" | |
local char | |
for (( i = 0; i < length; i++ )); do | |
char="${string:i:1}" | |
if [[ "$char" == [a-zA-Z0-9.~_-] ]]; then | |
printf "$char" | |
else | |
printf '%%%02X' "'$char" | |
fi | |
done | |
printf '\n' # opcional | |
} | |
urlencode "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment