Created
April 10, 2016 00:28
-
-
Save magnetikonline/b9f32aaa31d7dad6dd6cdd0babc4414e to your computer and use it in GitHub Desktop.
Pure Bash urlencode function.
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 | |
function URLEncode { | |
local dataLength="${#1}" | |
local index | |
for ((index = 0;index < dataLength;index++)); do | |
local char="${1:index:1}" | |
case $char in | |
[a-zA-Z0-9.~_-]) | |
printf "$char" | |
;; | |
*) | |
printf "%%%02X" "'$char" | |
;; | |
esac | |
done | |
} | |
encoded=$(URLEncode "my\value\will!be&encoded") | |
echo "$encoded" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment