Skip to content

Instantly share code, notes, and snippets.

@SomajitDey
Last active September 7, 2021 15:10
Show Gist options
  • Save SomajitDey/9e546c450f96309f70febe03b03ee5e0 to your computer and use it in GitHub Desktop.
Save SomajitDey/9e546c450f96309f70febe03b03ee5e0 to your computer and use it in GitHub Desktop.
url-encode and url-decode using bash and xxd
#!/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}"
#!/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