Skip to content

Instantly share code, notes, and snippets.

@jeremejazz
Created November 27, 2019 09:30
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 jeremejazz/757c5ce545826a690141fd0c4cb51255 to your computer and use it in GitHub Desktop.
Save jeremejazz/757c5ce545826a690141fd0c4cb51255 to your computer and use it in GitHub Desktop.
rawurlencode() {
local string="${1}"
local strlen=${#string}
local encoded=""
local pos c o
for (( pos=0 ; pos<strlen ; pos++ )); do
c=${string:$pos:1}
case "$c" in
[-_.~a-zA-Z0-9] ) o="${c}" ;;
* ) printf -v o '%%%02x' "'$c"
esac
encoded+="${o}"
done
echo "${encoded}" # You can either set a return variable (FASTER)
REPLY="${encoded}" #+or echo the result (EASIER)... or both... :p
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment