Created
July 15, 2014 16:46
-
-
Save jahed/58ea3ae520d26854d84b to your computer and use it in GitHub Desktop.
Shell script function to URL encode text
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
#http://stackoverflow.com/a/10797966/2913503 | |
urlencode() { | |
local data | |
if [[ $# != 1 ]]; then | |
echo "Usage: $0 string-to-urlencode" | |
return 1 | |
fi | |
data="$(curl -s -o /dev/null -w %{url_effective} --get --data-urlencode "$1" "")" | |
if [[ $? != 3 ]]; then | |
echo "Unexpected error" 1>&2 | |
return 2 | |
fi | |
echo "${data##/?}" | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment