Tom Ritchford
1 min readFeb 28, 2023

--

I've been using bash for… I don't even know how long, but easily 25 years. I've been using Python for almost 20 years.

I have a fondness for both, but at this point, any script with any complexity ends up in Python if at all possible.

For one thing, creating CLIs is far easier with Python and typer.

For another, basic things like arithmetic, associative arrays (dictionaries), and string manipulation are simply much easier in Python.

The only use for bash in my scripting, aside from tiny programs, is if I need pipes or tees.

For example, in a previous project, I needed to dump a huge database into a .sql file, compute a checksum, and then compress the file.

Unfortunately, this took the better part of a day to run these three jobs in sequence, but more, the disk space for the intermediate uncompressed dump was so large that it essentially doubled our peak disk usage.

All of this was being run from within a medium-sized Python framework, but the solution was obviously bash. In the solution we chose, Python prepared a single moderately complicated line of bash, which ran pg_dump, teed it into lbzip2 and also to sha256sum so we could do all three steps at the same time.

The result was a 40% reduction in peak disk space, and a 60% reduction in time.

--

--

No responses yet