Skip to content

Instantly share code, notes, and snippets.

@vikerian
vikerian / gist:283b6f80b5997ccfed08
Last active November 4, 2015 14:35 — forked from cdown/gist:1163649
Bash urlencode and urldecode
urlencode() {
# urlencode <string>
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9~_-]) printf "$c" ;;
[.]) printf "%s" "%2e" ;;
*) printf '%s' "$c" | xxd -p -c1 |