S
S
sv22042016-08-31 20:41:53
bash
sv2204, 2016-08-31 20:41:53

What is the correct way to insert variables from lua into bash?

What is the correct way to insert variables from lua into bash?
You need to pass 2 variables to the script, here is the code:

location /script { 
    content_by_lua '
      lua_arg1 = ngx.var.arg_arg1
      lua_arg2 = ngx.var.arg_arg2
      command = "/usr/bin/script.sh "..lua_arg1 ..lua_arg2
      local handle = io.popen(command);
      local result = handle:read("*a");
      handle:close();
      ngx.print(result);';
  }

Here is the request:
localhost:1501/script5?arg1=1234&arg2=4321
Here is the bash script
#!/bin/bash
echo argument1 $1
echo argument2 $2

And here is the result of
argument1 12344321
argument2
It turns out that the variables are "glued together", how to correctly transfer them individually to the script so that it would be like this:
argument1 1234
argument2 4321

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Lerg, 2016-08-31
@sv2204

Forgotten space

command = "/usr/bin/script.sh "..lua_arg1 .. " " .. lua_arg2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question