Last active
September 7, 2021 15:10
-
-
Save SomajitDey/9e546c450f96309f70febe03b03ee5e0 to your computer and use it in GitHub Desktop.
url-encode and url-decode using bash and xxd
This file contains 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
#!/usr/bin/env bash | |
# Ref: https://unix.stackexchange.com/questions/159253/decoding-url-encoding-percent-encoding | |
# Ref: https://github.com/sixarm/urldecode.sh | |
input="${@//+/ }" | |
echo -e "${input//%/\\x}" |
This file contains 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
#!/usr/bin/env bash | |
while IFS= read -r -N1 char; do | |
if [[ "${char}" =~ [-~[:alnum:]_.] ]]; then | |
echo -n "${char}" | |
else | |
echo -n "%$(echo -n "${char}" | xxd -p)" | |
fi | |
done < <(echo -n "${@}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment