1

How can I url-encode all characters in bash?

For example: abcd0123 => %61%62%63%64%30%31%32%33

I tried the built-in urlencode function in Linux but it only encodes special characters like (.?)

Cyrus
  • 84,225
  • 14
  • 89
  • 153
Raywando
  • 129
  • 5

1 Answers1

1

I don't believe this is possible in pure Bash, but other shell utilities can be strung together to achieve this result, for example

urlencode() {
    printf %s "$1" | od -An -tx1 -v -w${#1} | tr ' ' %
}
urlencode abcd0123 # => %61%62%63%64%30%31%32%33
ephemient
  • 198,619
  • 38
  • 280
  • 391