Re:Avoiding Bash frustration – Use Python for shell scripts
by alephu5 on Monday November 09, 2020 @02:27AM
(#25032182)
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
Re:Avoiding Bash frustration – Use Python for shell scripts
by dusted on Monday November 09, 2020 @09:18AM
(#25035011)
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.
Re:Avoiding Bash frustration – Use Python for shell scripts
by u801e on Monday November 09, 2020 @12:52AM
(#25031819)
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.
Re:Avoiding Bash frustration – Use Python for shell scripts
by bonestormii_ on Monday November 09, 2020 @03:23AM
(#25032535)
Maybe! I've only ever glanced at it, but something between awk and python does sound useful.
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.