如何 url 对 bash 中的所有字符(特殊和非特殊)进行编码
How to url-encode all characters (special and non-special) in bash
如何 url 对 bash 中的所有字符进行编码?
例如:
abcd0123 => %61%62%63%64%30%31%32%33
我尝试了 Linux 中内置的 urlencode 函数,但它只对特殊字符进行编码,例如 (.?)
我不认为这在纯粹的 Bash 中是可能的,但是其他 shell 实用程序可以串在一起实现这个结果,例如
urlencode() {
printf %s "" | od -An -tx1 -v -w${#1} | tr ' ' %
}
urlencode abcd0123 # => %61%62%63%64%30%31%32%33
如何 url 对 bash 中的所有字符进行编码?
例如:
abcd0123 => %61%62%63%64%30%31%32%33
我尝试了 Linux 中内置的 urlencode 函数,但它只对特殊字符进行编码,例如 (.?)
我不认为这在纯粹的 Bash 中是可能的,但是其他 shell 实用程序可以串在一起实现这个结果,例如
urlencode() {
printf %s "" | od -An -tx1 -v -w${#1} | tr ' ' %
}
urlencode abcd0123 # => %61%62%63%64%30%31%32%33