4 ms·
I suppose it's also true that your day-to-day development language may be someone else's glue language. There's probably hardware people who consider C their gl
by scott_s 15y ago
I suppose it's also true that your day-to-day development language may be someone else's glue language. There's probably hardware people who consider C their glue language.
I use Python for all of my scripts. The moment that I want to automate some system related task that requires any logic, I reach for Python. (I'd still write a bash "script" if the script was just a succession of commands.) I don't think this is a controversial position since Python is considered a cousin of Perl, and Perl was heavily inspired by shell scripts, awk and sed. I think of Perl and TCL as the original glue languages.
If I'm writing a script from scratch, I just don't see any compelling reason to do it in bash. (Or whatever your shell of choice is.) Yes, I recognize that "Python may not be available" is a potential reason, but it's not compelling to me because it's available in the places I'll need to work.
- pnathan 15y agoAgreed. 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.
- Goladus 15y agoI find bash to be more convenient in a few scenarios that basically fall into two major categories, which come into play whenever the script is simple enough that complex data structures (dicts, nested lists, etc) aren't very helpful. The first is when there are key external tools that work better than the python libraries and invoking them with subprocess or os.system is more cumbersome than just using bash. The second is when the implicit command-oriented nature of bash or syntax shortcuts makes for a much more succinct program. eg. 'do_thing && do_other_thing || fail' I'll admit though, my threshold for switching to python is not particularly high.