Skip to content

Instantly share code, notes, and snippets.

@janhicken
Last active October 29, 2024 08:05
Show Gist options
  • Save janhicken/b6e9361a5b5a64c3714f921217219569 to your computer and use it in GitHub Desktop.
Save janhicken/b6e9361a5b5a64c3714f921217219569 to your computer and use it in GitHub Desktop.
URL encoding in pure Bash
#!/usr/bin/env bash
set -o nounset
while IFS= read -r -n 1 char; do
case "$char" in
[-_.~a-zA-Z0-9])
printf %s "$char"
;;
*)
printf '%%%02x' "'$char"
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment