I'm doing a simple test to see if I can run a shell script in nginx easily. Lua seems a good solution. So I added
content_by_lua_block {
local myvar = "abcd"
local file = io.popen("myshellscript.sh myvar")
local result = file:read("*a")
ngx.say(result)
}
in my nginx.conf. In myshellscript.sh, I use echo "#1" to print the value of the parameter. But instead of seeing "abcd", I see "myvar" from the output. So what's the proper way to pass a variable as a parameter to the shell script in nginx lua? I know os.execute("myshellscript.sh myvar") can do the similar job as popen, but I don't know how to get the output to the stdout or the exit code from the shell script.