I started working in 2006 in a startup that make an heavy usage of Python. I quickly realize of powerfull it is, even if it was only Python 2.4. But I wasn't sure if Python will continue it's expension and I would have never believed that Python spread to this level. In 2006, there was only one way of scripting, tooling or instrumenting: shell! The situation has changed.
why bash?
Shell is a standard since the beginning of Unix because the native interface of Unix is terminal and your terminal interacts with the OS using Shell.
Bash have some advantages:
- no dependencies. It is installed by default on all distros. Most of the containers have bash
- bash is part of the skill set of every sysadmin
- basic file operations (copy, move, deletion) are simple and powerfull
Bash have some disavantages:
- syntax is not really eye candy and come directly from the dark ages of the 80's. Especially if you need arithmetic expressions or list
- function and parameters handling is really basic
- there is not extension possible except by calling an external binary
- the library concept is limited to import instruction or function with the
source
keyword
why python rather than bash
- it is a real programming language with objects and libraries to better structure your code
- you can debug your code using vscode for example
- you can extend Python using the Python/C Api
- the standard library includes a wide range of features that covers 95% of the basic usage
- Python is included by default in the major distros. For example CentOS come with a Python interpreter by default because its package manager (yum) is written in Python.
nowaday
In 2020, I would never recommand to use Shell except for simple and short scripts that don't need maintenance neither debugging. The following situations indicates that you should stop to use shell:
- you are using IO redirections to file and
grep -v
to simulate set operations - you are writing shell scripts with more than 200 lines or more than three functions
- you are spending a lot of time to debug by adding a lot
echo
s - you are thinking to split your shell script into different libraires and use
source
to include - you are calling binaries or other shell scripts with sensitive parameter like
--password
I know the power of usage and I know that people are often reluctant to change. But remember that it could worse if you realize your error too late. Two of the worst systems I have ever seen was made by more than 10.000 lines of code with interleaved layers of bash and Python. So if you are starting to write a new system from scratch think Python not bash.