How can I write a Lua script that will execute a command on the Linux terminal?

Viewed 856

I'm getting into scripting, and I understand the basics of Lua, but I don't know how I can run a command in the Linux terminal using Lua. When I say run a command I mean something like sudo apt install git or echo Pizza is delicious

1 Answers

You have a couple of options: if you want to run a lua script you have in a file script.lua, then lua script.lua should execute it. If you simply want to execute a couple of Lua statements, then you can use -e options: lua -e "statement1; statement2". See the Lua documentation for further details.

If you need to execute an external command from Lua, then you need to use os.execute: os.execute([[echo "first param" "second param"]]).

Related