3 ms·
I mean I guess but what's your plan when your script is just a bunch of subprocess.run calls? I promise you it won't be any less brittle.
by Spivak 2y ago
I mean I guess but what's your plan when your script is just a bunch of subprocess.run calls? I promise you it won't be any less brittle.
- tom_ 2y agoThe subprocess.run args argument is a list of strings, not a single string with whitespace-delimited parts, so you're all good quotingwise. This is now effortlessly a lot better than what you get with bash in terms of how brittle things are! Supply check=True and the script will barf on subprocess failure. Another useful upgrade.
- KingMob 2y agosubprocess.run() will happily accept a single string, though, so you may still inadvertently run into the issue anyway.
- deleted 2y ago[deleted]
- iamjackg 2y agoTake a look at https://sh.readthedocs.io/en/latest/ https://sh.readthedocs.io/en/latest/ for a very usable solution to easily run other processes in Python. It has made my life a lot easier whenever I've had to migrate a shell script to Python.
- IshKebab 2y agoI promise it will! It will handle weird filenames properly for example. But realistically it's rarely that simple and even when it starts that simple it will grow to not be. The downvotes are a very disappointing attitude.
- hamandcheese 2y agoShellcheck will prevent you from making any egregious whitespace errors. You can dynamically build up an arguments list using bash arrays. Errexit and pipefail options prevent you from ignoring errors. I agree that some work is better suited to a real programming language, however the driving force isn't the problems you speak of, which are trivial, it's when the logic/control flow of the overall problem becomes more complex.
- IshKebab 2y ago> Shellcheck will prevent you from making any egregious whitespace errors. It will try to prevent you. It isn't perfect though, and whitespace errors are only the tip of the iceberg. Shellcheck doesn't tell you to enable pipefail for example, so there's a huge foot-gun. Pipefail itself is kind of impossible to use correctly anyway.