首页 > 代码库 > url_encode and url_decode in Shell

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