Feb 242013

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.

  4 Responses to “Shell Script or Python Script/Program?”

Comments (3) Pingbacks (1)
  1. For those looking to mix shell scripts and Python, there is a great article at Linux Journal. It’s quite simple for Python to read and write with stdin and stdout. This makes Python a drop-in replacement:


  2. I’m also now looking into plumbum, which seems to be a very useful Python module (available through pip). I dug through about a dozen modules before settling on it – a lot of people have had a go at tackling this problem…

  3. Eliot, thanks for the link you provided in your comment. Very nice article!

Leave a Reply to Ugur Cancel reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(to be displayed above your comment)

(for moderation; your e-mail address will not be made public)