Last active
October 29, 2024 08:05
-
-
Save janhicken/b6e9361a5b5a64c3714f921217219569 to your computer and use it in GitHub Desktop.
URL encoding in pure Bash
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 | |
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