Re:Help Message for Shell Scripts
by hansdieter1337 on Tuesday July 07, 2020 @07:43PM
(#23765539)
Even better: Don’t use bash. I started using Python instead of bash. It’s way better to read and more maintainable. If I need the performance of native-Unix commands, I can still use them using subprocess.
[ Parent
| on HN ]
Python is not as handy/efficient as bash when you want to utilize some existing Unix commands. And normally it’s crucial to stop bleeding fast if something bad is happened to you server/cluster
Re:Help Message for Shell Scripts
by argonauts12 on Thursday July 09, 2020 @12:30AM
(#23776947)
I've been migrating shell scripts to python and have found the 'sh' library invaluable for pulling in pure CLI commands from the bash script and adding to the python implementation. http://amoffat.github.io/sh/
It's essentially an abstraction layer above subprocess. Quick example - to use ifconfig natively in python:
from sh import ifconfig print(ifconfig("wlan0"))
Python is surprisingly bad at managing subprocesses, though. Read the subprocess docs closely, it's quite easy to get deadlocks if you try to compose operations the way you can in bash.
There are libraries that fix that: https://pypi.org/project/sh/ if you are in position to use external libraries.
bash is everywhere
So is python
But which python?
Re:Help Message for Shell Scripts
by fredfjohnsen on Wednesday July 08, 2020 @10:30AM
(#23770212)