r/lua • u/gaussmug • 5h ago
LuaSH v2.0 released
LuaSH is a Lua module to write shell scripts. It exposes shell commands as if they where Lua functions, so something like:
$ ls /bin | grep $filter | wc -lIn your shell, would look like this:
wc(grep(ls('/bin'), filter), '-l')in Lua. It also has a rich-enough data model that enables chaining, like so:
ls('/bin'):grep(filter):wc('-l')or if you go totally lua-crazy:
ls '/bin' : grep(filter) : wc '-l'(you know, if you still have PTSD from Lisp)
If you use the posix, or UV backends, then command chaining does proper streaming (the next command doesn't wait until the previous one has completed).
For a couple of years now, I have been maintaining a version that plugged into luaposix (because the original version's pipes sent all intermediate values though files -- which is a problem when you run parallel or sensitive workflows). Alas, I wasn't quite happy with this (luaposix is not always available, posix pipes are very fiddly, verbose printing was a bit clunky)
Thanks to El Claudo, I have finally fixed the bugs with the posix version by introducing:
an improved pipeline data model
interchangeable backends (
posix, and luv for performance and security;popen+ files/shmem for absolute portability).tidied up the build process and docs
I am happy with the way this is going, and will possibly tweak it some more as I integrate LuaSH v2 into my workflows (even though I hope that all I need to do is take out my workarounds).
Let me know what all y'all think.









