0

I am trying to Loop through all the arguments, then I want it to be url encoded. It works currently but not with things like single quotes. Ex. What's the weather outside?

This is what I have tried:

for var in "$@"
    do
      n+="$var "
      done
      h="${n%?}"
      export h
      urlencode() { python -c "import os, sys, urllib as ul; print ul.quote_plus(os.environ['h'])"; }
      e=$(urlencode "$h")
      t=$(curl -s --request GET "http://example.com/?q=$e")
      echo $t
user3137578
  • 11
  • 1
  • 3
  • possible duplicate of [URLEncode from a bash script](http://stackoverflow.com/questions/296536/urlencode-from-a-bash-script) – Wrikken Jan 07 '14 at 23:12
  • @Wrikken If you read the post carefully, you will understand that it is not the URL Encoding that is broken. It just does not work with '. – user3137578 Jan 08 '14 at 01:59
  • If the urlencoding is not broken, why does it no work with `'` (and, for instance: why do you both export a variable _and_ provide a parameter)? But granted, the problem may be how you call it. I blindly assumed you'd so something like `./yourscripts "what's the weather outside"` and not something like `./yourscripts what's the weather outside`, which would not be an error in this script but in how you use bash – Wrikken Jan 08 '14 at 02:03

0 Answers0