I have a file named kong like this:
#!/usr/bin/env /usr/local/openresty/bin/resty
setmetatable(_G, nil)
pcall(require, "luarocks.loader")
package.path = "./?.lua;./?/init.lua;" .. package.path
require("kong.cmd.init")(arg)
I can execute it directly, like kong start.
But I want to use environment variables to modify the resty path freely. Such as I set an environment variable export CURR_RESTY_PATH="XXXX", then modify the kong like this
#!/usr/bin/env ${CURR_RESTY_PATH}
I will get /usr/bin/env: ${CURR_RESTY_PATH}: No such file or directory if kong start
My question is how can I modify the #!/usr/bin/env to use environment variable?
You can't. There are awful, ugly hacks -- but in the real world (where we need things to be reliable, even if interpreters are rewritten in the future to use two-pass parsers that
seek()back and reread their source files from the beginning), use a separate script.For example, you might rename your old
kongtokong.real, and then create akongscript that looks like this: