▲ | quotemstr 15 days ago | ||||||||||||||||||||||
People are generally bad about following their own advice. They're worst at following advice to avoid shell scripts. :-) We all know in theory we should move things to Python or another robust language once they become sufficiently complex, but in the moment, adding just this one feature takes precedence. Iterate "just one feature" a few times and you end up with a 1,000-line bash program. (The word "script" becomes inapplicable.) Now what? You want to add configuration support to your bash program? Well, you might as well use something robust to do it. | |||||||||||||||||||||||
▲ | pwdisswordfishz 14 days ago | parent | next [-] | ||||||||||||||||||||||
Which is why you rewrite in Python long before reaching that threshold. I start considering it as early as when I need to add any non-trivial command line parsing: argparse is just so much better than "while getopt". | |||||||||||||||||||||||
▲ | thyristan 14 days ago | parent | prev | next [-] | ||||||||||||||||||||||
This is why my threshold for not using any shell is "does it have more than one loop, more than one if-statement, an argument or file format parser or more than 10 lines?". Meaning that only very trivial things can be shell scripts and you rewrite early enough such that it isn't really a hassle or painful. | |||||||||||||||||||||||
▲ | theamk 15 days ago | parent | prev [-] | ||||||||||||||||||||||
It does not have to be all-at-once. Your bash program takes 10 input args and requires 15 env variables to be set? Don't reach out for that bash ini parser, create a python script which parses configs and invokes the original bash script. Next time you change feature, move it to python. Eventually you'll be mostly python. Something that helps greatly with that is that you can embed bash in python. So initial conversion can be as simple as file rename + 3 lines of code.
this lets you start by trivial .sh -> .py conversion, and then you can change one block at a time. Variables are tricky so do them first; or in the worst case, "declare -p" + "eval" + temporary files will save you. | |||||||||||||||||||||||
|