Skip to content

Instantly share code, notes, and snippets.

@tasoseng
Created March 27, 2021 00:28
Show Gist options
  • Save tasoseng/71d2105db2ad144e4839a21e52f8da7f to your computer and use it in GitHub Desktop.
Save tasoseng/71d2105db2ad144e4839a21e52f8da7f to your computer and use it in GitHub Desktop.
bash url decode
#!/bin/bash
urldecode() {
arg="$1"
i="0"
while [ "$i" -lt ${#arg} ]; do
c0=${arg:$i:1}
if [ "x$c0" = "x%" ]; then
c1=${arg:$((i+1)):1}
c2=${arg:$((i+2)):1}
printf "\x$c1$c2"
i=$((i+3))
else
echo -n "$c0"
i=$((i+1))
fi
done
}
urldecode "a%27b%27c"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment