Writing shell scripts is easy, but they’re often ugly. Writing Python is clean, but getting it to accomplish the same tasks isn’t always as easy.
I’ve been kicking around the pros and cons for a while. Many people choose simply based on what they already know, which only gives them that one option.
After reading A Clean Python Shell Script the conclusion started to form in my head:
- If there aren’t any arguments to pass in, it’s probably a shell script.
- If there isn’t much for control logic (besides a single loop or if/else) it’s probably a shell script.
- If the task is automation of command-line instructions it’s almost definitely a shell script.
Python is great for projects with complicated logic or utilities that take many different arguments. Similarly the logging capabilities are excellent if the project could fail in many different ways.
I suspect that if I have a project mixing this set of requirements, I might try calling the shell from Python rather than trying to shoehorn pipes and I/O redirection into Python.