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
  • 77,979
  • 13
  • 71
  • 125
Raywando
  • 29
  • 4

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
  • 189,938
  • 36
  • 271
  • 385