3 ms·
Agreed. I've been up to my armpits in other peoples' SH at times. It has a long list of defects which will come around and bite you. I have taken the policy of
by pnathan 15y ago
Agreed. I've been up to my armpits in other peoples' SH at times. It has a long list of defects which will come around and bite you.
I have taken the policy of moving any SH script I write to Perl (or Python) after it breaks about 45 lines (a page). I get good error checking, type checking, reliable escaping, and the ability to neatly abstract into modules.
So far, it hasn't hit me in the face yet. :-)
- mturmon 15y agoOf course everyone does what works for them. But I have to say that I think the 45 lines rule is not the best criterion. Lots of scripts which are of the form "move these files around, run this command on the files, mangle the output, send it to this command to summarize, send to another command to pretty-print" can be long in line count, but are really well-done in shell. Basically, operation sequencing, and/or line-by-line file processing. Shell makes it easy to ensure tempfiles are deleted, to catch signals, to automatically check error status of each and every command. As you note, sometimes shell is "contraindicated" (as they say in medicine). Anything needing data structures, or abstraction beyond simple functions, is not so good for shell.
- pyre 15y ago> reliable escaping One thing that I'm surprised about is that there is a severe lack of easy shell escaping of strings in more modern scripting languages. There should just be a printf symbol/modifier for it. I should be able to: sprintf("command %S %S", "blah blah blah", "blah -blah") to get command blah\ blah\ blah blah\ \-blah Also, take a look at: https://github.com/bsandrow/python-shellshock https://github.com/bsandrow/python-shellshock Let me know if you can think of anything that is painful to do in Python, but easy to do on the shell.