【发布时间】:2021-02-08 13:55:00
【问题描述】:
如何对 bash 中的所有字符进行 url 编码?
例如:
abcd0123 => %61%62%63%64%30%31%32%33
我在 Linux 中尝试了内置的 urlencode 函数,但它只编码特殊字符,如 (.?)
【问题讨论】:
如何对 bash 中的所有字符进行 url 编码?
例如:
abcd0123 => %61%62%63%64%30%31%32%33
我在 Linux 中尝试了内置的 urlencode 函数,但它只编码特殊字符,如 (.?)
【问题讨论】:
我不相信这在纯 Bash 中是可能的,但是可以将其他 shell 实用程序串在一起来实现这个结果,例如
urlencode() {
printf %s "$1" | od -An -tx1 -v -w${#1} | tr ' ' %
}
urlencode abcd0123 # => %61%62%63%64%30%31%32%33
【讨论】: