0

Im having a hard time figuring out why my variables ${coor1} and ${coor2} is not populated when used inside this curl

The curl itself works with static coordinates, but not when used with the variables, could anyone please point me in the right direction, thanks in advance :)

coor1=55.860734
coor2=9.808663

stored_address=$(
  curl -s "http://maps.googleapis.com/maps/api/geocode/json?latlng=${coor1},${coor2}&sensor=false" |
  grep -B 1 "route" |
  awk -F'"' '/short_name/ {print $4}')

echo "stored address = ${stored_address}"
Jens
  • 69,818
  • 15
  • 125
  • 179
BulletEyeDK
  • 65
  • 1
  • 8
  • 1
    Possible duplicate of [How to pass a variable in a curl command in shell scripting](https://stackoverflow.com/questions/13341955/how-to-pass-a-variable-in-a-curl-command-in-shell-scripting) – gile May 29 '17 at 06:50
  • 1
    The posted code works for me (output is Islandsvej). Voting to close as unreproducible. – tripleee May 29 '17 at 06:59
  • thanks for your comments, i'll view that other linked question, but still I wonder why my code works for others, but not for me... i've just checked that my curl package is up-to date – BulletEyeDK May 29 '17 at 07:08
  • Thanks for your comments, the code posted in the question works, it was an error from my own, as i missed a line with a variable $coor2 which i thought was # - but it was'nt... i ran curl - v for debug and found the error that way... – BulletEyeDK May 29 '17 at 10:32

1 Answers1

1

Try next tiny change:

coor1=55.860734
coor2=9.808663

stored_address=$(curl -s "http://maps.googleapis.com/maps/api/geocode/json?latlng="$coor1","$coor2"&sensor=false" | grep -B 1 "route" | awk -F'"' '/short_name/ {print $4}')

echo "stored address = "$stored_address

Output

stored address = Islandsvej
FieryCat
  • 1,875
  • 18
  • 28
  • Breaking the quoting most certainly does not solve the OP's problem. – tripleee May 29 '17 at 06:58
  • Thanks for your answer, your output sure is correct, but if I make the changes you suggest, I still have no output / empty variables – BulletEyeDK May 29 '17 at 07:00
  • @BulletEyeDK, but could you open cmd/console and ping it? Possibly it's a proxy issue? – FieryCat May 29 '17 at 07:22
  • Im running my bash enviroment in a virtual machine running ubuntu 12.04 LTS, it can without any problems ping the localhost, but it sure could be a proxy problem, as this is on a work PC at job, in a +500 employee company... im not sure how to control if this is a proxy issue – BulletEyeDK May 29 '17 at 07:33
  • @BulletEyeDK, if you're aware of proxy connection, just add it into your request `curl --proxy <[protocol://][user:password@]proxyhost[:port]> -s ...` – FieryCat May 29 '17 at 07:49
  • Thanks for this useful tip, i've just been talking to one of the IT administration empolye'es, but the one knowing anything about a possible proxy is not a work today, will report back when im further in this issue ;) – BulletEyeDK May 29 '17 at 08:22
  • It was not a proxy problem.... actually the code worked as intended, but I had a linje with $coor2 which I somehow thought i had made # for, so an clear error from my own part. – BulletEyeDK May 29 '17 at 10:29
  • I ran the curl with -v for debug and found the error that way... thanks for helping me out none the less... – BulletEyeDK May 29 '17 at 10:30