2016-04-08 2 views
0

Ich versuche, eine Google Geocode-Suche als eine Variable in BASH zu speichern.BASH-Skript zum Speichern einer Google Geocode API-Suche als Variable

Hier ist, was ich mit (oder so ähnlich) wollen am Ende

_GEOINFO=$(curl "http://maps.googleapis.com/maps/api/geocode/json?address="$_WHERE"" 

Hier ist, was funktioniert fast:

_CITY="Grand rapids" 
_STATE="Michigan" 
_COUNTRY="United States of America" 
_WHERE="\"$_CITY\",\"$_STATE\",\"$_COUNTRY\"" 
curl "http://maps.googleapis.com/maps/api/geocode/json?address="$_WHERE"" 

Hier ist, was nicht:

curl "http://maps.googleapis.com/maps/api/geocode/json?address=$_WHERE" 

Ich habe so viele verschiedene Variationen anprobiert escaaping:

\"$_WHERE\", \'\"$_WHERE\"\', \"${_WHERE}\", 

Für die meisten Dinge, die ich versucht habe, ich einen Fehler zu sagen:

parse error: Invalid numeric literal at line 1, column 10 
+0

Übrigens, wenn Sie eine Suche wie Toronto, Ontario, Kanada machen, wird es funktionieren. Aber für die USA nicht. – user2470057

Antwort

0

IT FIXED!

# store location information into variables 
_CITY="Grand rapids" 
_STATE="Michigan" 
_COUNTRY="United States of America" 

# store all information as one string 
_WHERE="$_CITY,$_STATE,$_COUNTRY" 

# replace spaces with a + 
_WHERE="${_WHERE// /+}" 

# store the geo-location information into a variable 
_GEOINFO=$(curl "http://maps.googleapis.com/maps/api/geocode/json?address=\"$_WHERE\""