Our great sponsors
-
WorkOS
The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.
-
oil
Oils is our upgrade path from bash to a better language and runtime. It's also for Python and JavaScript users who avoid shell!
-
music-explorer
A music scraper, navigator, archiver, and cataloger for people looking for new sounds.
-
InfluxDB
Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
But also please consider using Shellcheck if you do:
* https://www.shellcheck.net
> Oh, and that 500-line shell script probably ends up being a 5000-line Python monster anyway.
The dehydrated ACME client is 2400 lines of bash/zsh:
* https://github.com/dehydrated-io/dehydrated
And its external dependencies are OpenSSL and cURL. The acme.sh shell ACME client is 8000 lines of shell:
* https://github.com/acmesh-official/acme.sh
The official Let's Encrypt client is written in Python, and the core 'executable' is much longer, and in addition it pulls in a boatload of dependencies:
* https://packages.debian.org/bullseye/python3-certbot
> Oh, and that 500-line shell script probably ends up being a 5000-line Python monster anyway.
The dehydrated ACME client is 2400 lines of bash/zsh:
* https://github.com/dehydrated-io/dehydrated
And its external dependencies are OpenSSL and cURL. The acme.sh shell ACME client is 8000 lines of shell:
* https://github.com/acmesh-official/acme.sh
The official Let's Encrypt client is written in Python, and the core 'executable' is much longer, and in addition it pulls in a boatload of dependencies:
* https://packages.debian.org/bullseye/python3-certbot
> Possible? Maybe. Easy? No. Especially the “testable” part.
a testable shell script? Never seen one.
Thinking about scirpts I've read in the past, I remember seeing Jason Donenfeld's bash script for wireguard-wg and thinking how productive and readable it was,
https://github.com/WireGuard/wireguard-tools/blob/master/src...
The oil shell is an attempt to move forward:
https://www.oilshell.org/
Bash is turing-complete, so it's possible to write automated test cases in bash. Example: https://github.com/vlisivka/bash-modules/blob/master/bash-mo...
I'm a big fan of not posix bit instead modern bash and to all the complainers about dash and ash, I say "tough cookies".
Sometimes I'll even use zsh
Here's some example of a modern tool I have written for a subject I call "music discovery"
https://github.com/kristopolous/music-explorer/tree/master/t...
You'll see many languages in there.
If you don't like my practice then I guess don't use it. I've been using/developing these particular tools nearly every day for over 3 years and it works well for me.
I'm not going to say bash is awesome but it's pretty great for programming.
I use zsh as my interactive though
Shell scripting's best kept secret is babashka (https://babashka.org/).
- It's a flavor of Lisp (Clojure, specifically), a language whose flexibility makes it ideally suited for gluing together programs and working with data
If you code in Python, your probably should use the language as much as possible and avoid calling shell commands.
E.G:
- manipulate the file system with pathlib
- do hashes with hashlib
- zip with zipfile
- set error code with sys.exit
- use os.environ for env vars
- print to stderr with print(..., file=...)
- sometimes you'll need to install lib. Like, if you want to manipulate a git repo, instead of calling the git command, use gitpython (https://gitpython.readthedocs.io/en/stable/)
But if you don't feel like installing a too many libs, or just really want to call commands because you know them well, then the "sh" lib is going to make things smoother:
https://pypi.org/project/sh/
Also, enjoy the fact Python comes with argparse to parse script arguments (or if you feel like installing stuff, use typer). It sucks to do it in bash .
If what you need is more build oriented, like something to replace "make", then I would instead recommend "doit":
https://pydoit.org/
It's the only task runner that I haven't run away from yet.
Remember to always to everything in a venv. But you can have a giant venv for all the scripts, and just she-bang the venv python executable so that it's transparent. Things don't have to be difficult.