Skip to content

Instantly share code, notes, and snippets.

@josefsalyer
Created April 23, 2018 16: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 josefsalyer/181249df24d8131f5b8115a161d08bb3 to your computer and use it in GitHub Desktop.
Save josefsalyer/181249df24d8131f5b8115a161d08bb3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
encode()
{
local string=$1
local strlen=${#string}
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
}
echo $(encode $1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment