Last active
June 20, 2024 12:06
-
-
Save westfly/ed7e25ee4353751d94132f92837a7074 to your computer and use it in GitHub Desktop.
urlencode for shell
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
function 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 [[ $? == 0 ]]; then | |
echo "${data##/?}" | |
fi | |
return 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A bash script that works based on the one in this gist: