Skip to content

Instantly share code, notes, and snippets.

View jahed's full-sized avatar

jahed.dev jahed

View GitHub Profile
@jahed
jahed / urlencode.sh
Created July 15, 2014 16:46
Shell script function to URL encode text
#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