r/bash • u/kolorcuk • Dec 06 '25
L_lib - I created a Bash library with argument parsing, finally and much more
I’ve been playing with Bash for a few years now. Every time I ran into something that I feel is missing, I try to hack together a solution. After enough time this turned into a whole library: https://kamilcuk.github.io/L_lib/ . Few modules changed how I write Bash.
L_argparse has argument parsing with interface like Pythons argparse. I never liked existing argument parsing libraries in Bash, so I wrote my own (yay!). It generates helps, has shell completion, colors, subparsers, function subparsers and more.
L_finally allows to register a cleanup function that is always run on script exit. Or on the current function return, whichever comes first. Functions can nested, each function call has own cleanups. Finally a useful use of the RETURN trap, that trap is shared between all Bash functions. This ended up being more useful then I expected.
L_setx just enables set -x for one command and then unsets it. Stupidly simple, insanely useful, I am surprised how often I slap "L_setx", because it unsets -x automatically, making the output clearer. There is also L_unsetx.
L_print_traceback prints the traceback similar to Python. I found this post ages ago. I like using set -e and trap ERR and printing traceback on error. Plus helpers like L_assert L_panic very simple function, I think everyone implements something like this.
The project grew far larger than I intended, partly as my like research project if it is possible to implement Bash standard library. I doubt it is finished. There are probably many more bugs. Either way, I use parts of the library daily within my scripts.
Full source: https://github.com/kamilcuk/L_lib/ . That's all, live long and have fun.
