
We’ve all heard that Python is a scripting language, and there’s a lot of people who say that Python replaces bash entirely.
What is bash?
Bash is what is running when you open the terminal. It’s the “shell” developers talk about often. It’s been the default on Linux forever and on macOS until they switched to zsh in 2019.
Bash is essentially the glue of the UNIX world; it allows you to:
Chain system commands
Automate repetitive shell tasks
Talk directly to the OS
Bash is quite literally everywhere: Linux servers, CI runners, Docker containers, etc.
» If you’re looking for a career in software, most 4 year degree program typically doesn’t teach you Bash. MIT has a course that is called “The Missing Semester of Your CS Education” which includes bash - here’s the course.
Where Bash Shines over Python
Reaching for Python because it’s what you know (especially in the age of AI) may not be (and is likely not) the best option.
For instance, writing something such as subprocess.run([“ls”, “la”]) is worse than just running ls -lah in the command line. The reason being is because of the overhead needed to start a Python interpreter - you need everything that a normal Python program needs to run just to run that single command.
» Bash was written to interface directly interface with the operating system and ensure guaranteed availability on most Unix/Linux systems.
Bash wins when you’re gluing things together (i.e. chaining). For instance, if you’re looking for all log files and trying to count the number of errors, in Bash you’d write:
find . -name "*.log" | xargs grep "ERROR" | wc -lBut in Python, you’d probably write it as:
from pathlib import Path
count = sum(
1
for f in Path(".").rglob("*.log")
for line in f.open(errors="ignore")
if "ERROR" in line
)
print(count)While the Python is much easier to read, a one-off command in terminal written with bash is significantly more efficient not only in terms of execution time, but also with developer’s time.
» The start-up time of a bash shell script is 2.8 milliseconds, while that of a Python script is 11.1 milliseconds (source). But let’s be honest - this is unnoticeable to us humans.
Where Python Shines over Bash
Python shines over bash when scripts start doing some serious work - parsing data and handling errors, for instance. Take parsing a CSV with messy data:
awk -F',' '$3 > 25 {print $1","$2}' users.csv > filtered.csvYikes, this is hard to read. You also have to consider if there’s items such as missing columns, inconsistent casing, or even quoted fields. Sure you can get AI to write a bash script to handle this for you, but it’s super hard to read.
» Fun exercise: prompt Claude or ChatGPT with the following: “Take the following awk script and account for missing columns, inconsistent casing, or even quoted fields: awk -F',' '$3 > 25 {print $1","$2}' users.csv".
Instead, you can use Python:
import pandas as pd
users = pd.read_csv('users.csv')
filtered = users[users['age'] > 25][['name', 'email']]
filtered.to_csv('filtered.csv', index=False)Same result, handles edge cases, and when you come back to the code you know exactly what it does.
Another area where Python would be better is when you’re working with HTTP requests. You can call an API in Bash with curl, but the moment you need to check response codes, parse JSON, or retry on failure, you’ll probably wonder why you even chose Bash to begin with (another fun exercise: have Claude/ChatGPT print this script out).
So… Does Python replace Bash?
No, but yes - only in certain scenarios.
It doesn’t “replace” it in the way we think it would. Python replaces bad Bash. Bash scripts that have gotten too big or do real heavy data work would most likely benefit if it were a Python script.
On the contrary, Bash outshines Python in instances where you’re gluing tools together, like in the command shown above when looking for the number of errors in log files.
Happy coding!
If you used AI to generate the scripts mentioned here, what was the result? How did it make you feel, and would you prefer using Python in these scenarios? I’m curious to know - reply back with your response!
📧 Join the Python Snacks Newsletter! 🐍
Want even more Python-related content that’s useful? Here’s 3 reasons why you should subscribe the Python Snacks newsletter:
Get Ahead in Python with bite-sized Python tips and tricks delivered straight to your inbox, like the one above.
Exclusive Subscriber Perks: Receive a curated selection of up to 6 high-impact Python resources, tips, and exclusive insights with each email.
Get Smarter with Python in under 5 minutes. Your next Python breakthrough could just an email away.
You can unsubscribe at any time.
Interested in starting a newsletter or a blog?
Do you have a wealth of knowledge and insights to share with the world? Starting your own newsletter or blog is an excellent way to establish yourself as an authority in your field, connect with a like-minded community, and open up new opportunities.
If TikTok, Twitter, Facebook, or other social media platforms were to get banned, you’d lose all your followers. This is why you should start a newsletter: you own your audience.
This article may contain affiliate links. Affiliate links come at no cost to you and support the costs of this blog. Should you purchase a product/service from an affiliate link, it will come at no additional cost to you.

