News for hackers. Stuff that matters.
Re:Hush, a modern shell scripting language by gorgoiler on Monday April 25, 2022 @11:08PM (#31163561)
This is very true, particularly if your script is just an imperative list of commands to run.

Python scripts win when you actually need to handle errors, or non trivial output parsing, or when the concept of “list of things” doesn’t fit neatly into the “lines of text / pipe symbol” paradigm.

I try to think of it like Donkey Kong. Every time you do something like this:

  var=$(command | awk -vID=$ID ‘$6 ~ /foo/ and $7 == ID {print $1 “ “ $2} | head -3)
…you get hit by a barrel. Three hits and you turn it into a Python module with a __main__.py or an if __name__ == “__main__” at the bottom.

If it’s a truism that most shell scripts are better off written in Python, it’s just as true that all Python scripts are better off as reusable modules (that may also be standalone scripts.)

There are no comments on this comment yet.