Kalib Zen
Kalib Zen

Reputation: 925

Concatenate string variable in lua when using io.popen command

I want to concatenate this string called test inside the URL but it doesn't seem to work:

test = "1.1.1.1"
local geoip = io.popen("wget -qO- 'https://api.ipgeolocationapi.com/geolocate/' .. test  .. '":read():match'"name":"(.-)"')
print(geoip)

I got this error:

lua: hello.lua:3: ')' expected near ':'

I also tried doing like this way but I got the same error:

test = "1.1.1.1"
command = "wget -qO- https://api.ipgeolocationapi.com/geolocate/" .. test
local geoip = io.popen(command:read():matchname":"(.-)"')
print(geoip)

The url should append the test string. Any idea how to achieve this ?

Upvotes: 1

Views: 440

Answers (1)

Alexander Mashin
Alexander Mashin

Reputation: 4617

You need to fix your quotes and parentheses; your test is inside a string literal and read and match are inside io.popen call:

local geoip = io.popen ("wget -qO- 'https://api.ipgeolocationapi.com/geolocate/" .. test .. "'"):read ():match '"name":"(.-)"'

Upvotes: 3

Related Questions