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}"
4
  • 1
    Possible duplicate of How to pass a variable in a curl command in shell scripting Commented May 29, 2017 at 6:50
  • 1
    The posted code works for me (output is Islandsvej). Voting to close as unreproducible. Commented May 29, 2017 at 6: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 Commented May 29, 2017 at 7: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... Commented May 29, 2017 at 10:32

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

8 Comments

Breaking the quoting most certainly does not solve the OP's problem.
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, but could you open cmd/console and ping it? Possibly it's a proxy issue?
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, if you're aware of proxy connection, just add it into your request curl --proxy <[protocol://][user:password@]proxyhost[:port]> -s ...
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.