Hacker News new | ask | show | jobs
by bonestormii_ 2055 days ago
For scripts requiring any degree of complexity regarding data structures or architecture, for sure, use Python.

But like, you can't just use Python to interact with your system. It will be such a pain in the ass.

Piping and redirection in Bash is a million times more concise and expressive. Working with streams like this is what it excels at. But if you need to to populate some data structure and access data by key... python is better.

Python's import system requires multiple lines. Python's spacing requirements require multiple lines and awkward spacing when typing directly in the shell. Sometimes you are writing a script, and sometimes you just want to do ${action} to ${file}_${i} in the directory.

You owe it to yourself to be proficient in bash if you are working a lot in a unix-like environment.

3 comments

When I have a lot of systems stuff combined with some algorithmic stuff, I'll often write out the latter in a python script and incorporate it into the bash script. Overall seems to work quite well, you can even put it in the same file to assist distribution
I often use jq for working with more complex data structures in bash, sure it's not built-in, so you're forced to extract some stuff into variables before interacting with it, but that often leads to cleaner code anyway.
I think a lot of your points could be addressed by using perl instead, and it's a lot more flexible in terms of manipulating text rather than using a combination of utilities like awk and cut.
Maybe! I've only ever glanced at it, but something between awk and python does sound useful.