url_encode and url_decode in Shell

Posted westfly

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了url_encode and url_decode in Shell相关的知识,希望对你有一定的参考价值。

之前写过一版 shell下解码url,下面给出另外一个版本

from https://gist.github.com/cdown/1163649

function urlencode() {
    local LANG=C
    for ((i=0;i<${#1};i++)); do
        if [[ ${1:$i:1} =~ ^[a-zA-Z0-9\\.\\~\\_\\-]$ ]]; then
            printf "${1:$i:1}"
        else
            printf \'%%%02X\' "\'${1:$i:1}"
        fi
    done
}
urldecode() {
    # urldecode <string>

    local url_encoded="${1//+/ }"
    printf \'%b\' "${url_encoded//%/\\\\x}"
}

好用就行

以上是关于url_encode and url_decode in Shell的主要内容,如果未能解决你的问题,请参考以下文章

shell 解码url   url decode

为啥0and1=0

(OrElse and Or) and (AndAlso and And) - 啥时候使用?

Alert and Action sheets and Timer and Animation

D. Kuro and GCD and XOR and SUM

pure and dirtyasl