lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Tue, Mar 6, 2012 at 4:35 PM, Benjamin Ong <human_pitchpipe@hotmail.com> wrote:
Hi,

is it possible to use lua to modify the current shell with system calls? I tried:
    os.execute("shopt -s expand_aliases")
but this executes the call in a system shell, not the current shell.

 thanks

~ ben

Hi Benjamin,

do you think that the code below could do what you need?
The shell function "mylua" works like "lua", but after running the Lua
interpreter it executes the shell commands stored in /tmp/to.sh in the
current shell context... Hint: if "source" looks unfamiliar, see:
http://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html

  function mylua () {
    echo -n > /tmp/to.sh
    lua $*
    source /tmp/to.sh
  }

  # Test:
  mylua -e '
    toshell = function (str)
        f = assert(io.open("/tmp/to.sh", "w+"))
        f:write(str)
        f:close()
      end
    toshell("cd /tmp/")
  '

Cheers,
  Eduardo