首页 > 代码库 > shell 解码url   url decode

shell 解码url   url decode

文件名:url_decode.sh
#/bin/sh
awk ‘BEGIN{
for(i=0;i<10;i++)
    hex[i]=i;
    hex["A"]=hex["a"]=10;
    hex["B"]=hex["b"]=11;
    hex["C"]=hex["c"]=12;
    hex["D"]=hex["d"]=13;
    hex["E"]=hex["e"]=14;
    hex["F"]=hex["f"]=15;
}
{
    gsub(/\+/,"");
    i=$0;
    while(match(i,/%../)){
        if(RSTART>1);
            printf"%s",substr(i,1,RSTART-1);
            printf"%c",hex[substr(i,RSTART+1,1)]*16+hex[substr(i,RSTART+2,1)];
            i=substr(i,RSTART+RLENGTH);
        }
        print i;
    }‘

echo $url | ./url_decode.sh

shell 解码url   url decode