Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I've been shopping around for a scripting language to replace Bash for commandline stuff, which also doesn't have a significant startup time, is Lua something I should look at?


The closest are Python, Ruby, Perl. IMHO Lua is best as plugin/scripting language operating on some object API. E.g. Nginx (OpenResty) and Roblox use it that way.


I have attempted to use Lua for shell scripting in the past and I agree with this assessment. I recently started learning Ruby specifically for shell scripting and find it to be the most ergonomic / productive.


Idk about lua, but uv single file python scripts (search the phrase) may be highly relevant for you. Or pure python, if you don't need to pull in any dependencies.


Python startup times suck though. On my system `python3 -c 'print("hello world")'` takes 60-70ms. In contrast equivalents with bash or lua both are in 1-2ms range. The difference is definitely noticeable.


Know your tools. If you're writing a script you run once in a while, 60-70ms is meaningless. If you're running it 10x a minute or more, sure reach for that fast startup language.

As comments here suggest, lua isn't much of a bash replacement. Happy to hear your alternatives and suggestions for bash.


OP did explicitly mention startup time as one of their criteria though


I try to keep very few programming rules, but one which has emerged over time is "no python unless absolutely necessary" (precisely because of the thing you hinted at- the dependency problem, which I've run into one time too many, but also, the whole concept of there being only 1 way to do things which is kind of enforced just always rubbed me the wrong way)

But yes, in theory, that might be nice! There's also the Python-powered shell, Xonsh, which I can't use either.


Dependency problems are mainly resolved with uv - try it.

1 way to do things - not sure what you mean. It's a general purpose language, if you dont like something there's probably a different library that may do it the way you like (eg, don't like exceptions, use a library that mimics rust style Result values; don't like oop, don't do oop, functional programming is certainly possible in python), or easy enough to start creating your own private utility libraries that do things your way.

Xonsh was okay. Idk if I'd use it again. I'd probably just use python to invoke external cli programs using subprocess. I used xonsh for scripting before. I recall it having a slightly slow start up - I launch shell frequently so that's a no-go for me to use as my default shell.

---

And I looked at alternative scripting languages. Racket, D (has a single file script mode), ocaml, etc. Honestly python seemed good enough, even with its warts, especially with uv to manage deps without a whole formal project needing to be setup for a script. Stwp up from bash. Most of my use cases are fine with argparse + subprocesses + a unix shebang at the top + "chmod +x", with uv handy if I need a external library.


Btw: MicroPython is also available as a binary for all the usual operating systems. I’ve once made a few scripts and some .sh and .cmd files to launch them using the bundled micropython binary.


Racket intrigued me, what did you find with it?


In that case, also check Zuo.

https://docs.racket-lang.org/zuo/index.html

Zuo is used to build Racket. It can be distributed as a single C file, which makes it extremely to integrate in new projects.


It's a really bad choice for a Bash replacement

You have to reinvent the wheel every other day since the standard library doesn't come with much included


That's the main reason people have so mixed opinions about the language.

If you're stuck with the standard library (hello gsub!) and the application-specific library is an incoherent collection of functions, you're going to have a really bad time. That's the case too often because it's easier to plug the VM into an existing program than it is to create bindings that are not painful to use.

OTOH a well thought out environment makes you forget you're programming in Lua.


I don't need to forget that I'm programming in Lua, I think it's a great little language

Just terrible standard library


Have there been any unofficial attempts to make a stdlib for it?



nah


it has no regex? eeek


What I hate with passion is that the first thing you do is write your own pseudo-regex wrappers for missing string manipulation functions you'd consider standard in other languages.


It seems that it has something that is close enough to regex to do the job most of the time


I'd be happy for someone to correct me, but the Lua and LuaJIT repls don't seem very pleasant to use. Lua's standard library is also very barebones and... idiosyncratic, which makes it annoying to use as a Bash replacement.

I'm sure there are plenty of libraries out there to rectify those issues, though.


Yes you should.

You'll need a glob function, cd/getcwd/setcwd, pretty-printer. That's about it.

Lua stdlib replaces sed, awk, grep, cut, tr, tail, etc.

Startup time is the best. In my testing, a lua script that functions like `echo` runs faster than echo.


> In my testing, a lua script that functions like `echo` runs faster than echo.

this is kind of hilarious

lua must be severely optimized at this point


so I finally got a luajit and some standard libs working together in my environment

the reason why it took so long is I use nixos and nix-darwin and... well, you know... it was non-obvious how to get everything working together "because Nix" but with the help of a good LLM I figured it out.

HOLY HELL IS THIS FAST.

i had the brand new chatgpt 4.1 rewrite a name=value pretty-printer terminal function from elixir (which I used because it was easy and maintainable, but at the cost of the VM startup) to lua.

272ms for the elixir version (`env | name-value-to-table`) vs. 17ms for the Lua version (`env | name-value-to-table-lua`). WOW. 1/16 the time LOL.

anyway here is that rewrite https://gist.github.com/pmarreck/47e110cbc62ea6603a0e61543d2...

Guess I'm gonna have to keep this in my toolkit! (And now that I figured out the Nix, it will remain easy!) Thanks!


I'm having a great time with Babashka in my ~/.local/bin




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: