Last active
April 5, 2020 14:28
-
-
Save meleu/2290a2fcc9bf979d99b1003bb05c72f8 to your computer and use it in GitHub Desktop.
urldecode the contents of a file and print it in standard output.
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
#!/usr/bin/env bash | |
urldecode() { | |
local encoded="${*//+/ }" | |
printf '%b\n' "${encoded//%/\\x}" | |
} | |
main() { | |
local file="$1" | |
local line | |
if [[ -z "$file" ]]; then | |
file='/dev/stdin' | |
echo "WARNING: no filename given, reading from stdin." >&2 | |
elif [[ ! -f "$file" ]]; then | |
echo "ERROR: invalid file '$file'" >&2 | |
echo "USAGE: $0 [filename]" >&2 | |
exit 1 | |
fi | |
while IFS= read -r line || [[ -n "$line" ]]; do | |
urldecode "$line" | |
done < "$file" | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment