Member-only story
Bad Bash Habits You Can Fix in Minutes
Simple Changes, Big Improvements
4 min readApr 16, 2025
Bash is powerful but it’s also easy to mess up in ways that seem harmless… until they bite you later.
Here are few bad Bash habits that many developers fall into and how you can fix them in minutes.
- Using
ls | grep
instead of shell globbing
ls | grep '\.txt$'
Why its Bad:
- This creates an unnecessary subprocess (
ls
) and pipes it into another subprocess (grep
). - It’s slower and breaks with weird filenames (e.g., ones containing newlines or special characters).
- It assumes filenames don’t contain whitespace or special characters, which is fragile.
Better:
ls *.txt
- Shell globbing (
*.txt
) is more efficient and direct. - It doesn’t involve a pipe or an extra process.
- It works predictably and faster — especially when dealing with many files.
2. Useless use of cat
cat file.txt | grep 'error'
Why Its Bad:
- You’re spawning an unnecessary
cat
process. - It makes the command harder to read and breaks idiomatic Bash…