I wrote bash scripts for several years now. You can find old bash scripts of mine on GitHub but most of them aren’t maintained anymore - and I have a reason for that.
But before I give you my reasons for not using many bash scripts anymore, lets look at the benefits of bash:
- It super easy and you basically already can it if you write Linux / BSD commands
- There are frameworks out now which give you advanced features like testing
- It works out of the box on nearly every Linux / BSD system
Okay - sounds good - so whats my problem?
Bash is limited. E.g. it doesn’t work out of the box in Windows and I switched my default shell in Linux to fish. But let’s break down a few points why Bash isn’t optimal for me:
- You tend to write platform specific code - e.g. I switched from Debian to Arch Linux and had to replace the
- I use fish as default shell. You can use Bash-Scripts with fish, but it’s more complicated …
- Linux isn’t my only operating system - I run Windows and macOS machines as well.
- I love features of higher level programming languages like Python.
And how does Python solve this problem?
- It runs out of the box on many Linux systems
- It’s cross platform - the same code can run under Linux, Windows, macOS, … but you also can check the current system and write platform specific code for that
- It is also super easy and makes fun
- Testing and more advanced features are build in - no need to install packages
- Like bash it is already used for automating tasks in many systems (so you can find tons of help online)
- You can simply access the operating system
- Distribution is also very simple - just create a package and pip can install it from the PyPI, private registry or a Git-Repo
Languages like Go would also be interesting for automating tasks in your Linux system but Go has things like pointers and types. Python is more similar to Bash - very simple without advanced topics like types or pointers.
I created many python scripts for things which solved bash scripts before. And my python scripts all have unit tests and detect the current running operating system. Whereas my bash scripts only worked on Debian systems do my python scripts work on all my used operating systems. So it has saved me a lot of work.
But I also continue to use little bash scripts for simple tasks like “open this on startup” - I think its important to be aware, that higher level languages like python have a big benefit if you want to switch your system but use the same scripts.