【问题标题】:How to url-encode all characters (special and non-special) in bash [duplicate]如何对bash中的所有字符(特殊和非特殊)进行url编码[重复]
【发布时间】:2021-02-08 13:55:00
【问题描述】:

如何对 bash 中的所有字符进行 url 编码?

例如: abcd0123 => %61%62%63%64%30%31%32%33

我在 Linux 中尝试了内置的 urlencode 函数,但它只编码特殊字符,如 (.?)

【问题讨论】:

    标签: bash url encode


    【解决方案1】:

    我不相信这在纯 Bash 中是可能的,但是可以将其他 shell 实用程序串在一起来实现这个结果,例如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多