Better bash scripting in lua

An AI image depicting the time when I coded a lua module.
An AI image depicting the time when I coded a lua module.

I made a new lua module called "bash". It provides two functions that handle most of my actual bash use cases.

  1. bash.shell(cmd,_timeout)-->stdout_text,stderr_text,status
  2. bash.shush(cmd,_timeout)-->stdout_text,stderr_text

Both functions call error() on system errors, such as out of memory, or can't fork, or can't create or read a pipe, or other such errors. Additionally, they will call error() if the command times out. The timeout arg is optional. The shush function will additionally call error() if the command's status is nonzero.

Lua's io.popen will get you the output of a command, but not the status code. os.execute will get you the status code, but not the output, bash.shell gets both and also the stderr output.

The module is only for linux and it requires "/bin/bash".

I don't have code to share because I am still testing it. So, I guess this is just a tease. The bash module will be in a future version of the Lulua Lua Distro.

[Update Jan 2nd] Wow! I asked AI for code review. Results were mixed. It did point out some things that I did miss, but it also sent me on some wild goose chases, and it gave me some terrible code suggestions (if only it could take its own advice). AI really requires an expert operator. Overall, I am not very impressed.