Is it possible to assign a variable to a variable in a shell script?

Is it possible to url encode a variable in a shell script?

#!/bin/bash 

now=$(date +"%T") 

DATA=$(wget -q -O -   "http://someurl.com/x.htm?callback=webRequest&exthrs=1&extMode=&fund=1&entitlement=0&skipcache=&extendedMask=1&partnerId=2&output=json&noform=1")

wget -q -O - "http://somewhere.com?abc=$1&responseData=$DATA"

echo "-----COMPLETE----- $now   $1 $RANDOM  
"

      

I want url to encode a DATA variable since its results have in it too, it messed up the parameters in the second wget, is there a way to encode this DATA variable without using PHP to encode the url?

+3


source to share


1 answer


Here is one way to encode the shell url string DATA

:

DATA=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])"  "$DATA")

      



Here's another one:

DATA=$(perl -MURI::Escape -e 'print uri_escape($ARGV[0]);' "$DATA")

      

+3


source







All Articles