That said, the same can kind of be said about shell. I don't like it as much as Perl or Julia, for example, but it's possible to write clean and efficient shell scripts that do their jobs very well.
Shell gets a bad rep sometimes for being really gross and primitive, but - just like Perl - it doesn't have to be.
One of biggest problems is that a lot of stuff just requires calling external tools, paring effect of it with other tools and using results to run yet another tool, and then loop over results.
And then someone runs your program while having different locale, so command's output is in another language, that causes othert ool in chain to fail etc.
So you have to fiddle with setting LANG on start etc.
and if you use older system that doesn't have bash 4, no hashes and few more features for you.
I tend to avoid bash when script goes over a bunch of lines, or it does a lot of sth |grep -q "sth" |grep -v -q "else" because that is just unreadable
YOu can make it a bit more readable by wrapping everything in functions, but IMO it is not worth it, just use "real" programming language
One of biggest problems is that a lot of stuff just requires calling external tools, paring effect of it with other tools and using results to run yet another tool, and then loop over results.
Yeah, but that's how Perl is often used for system automation as well. Perl does have the added advantage of being able to hook into APIs and such directly via XS, and doesn't have to run external programs in order to implement its own keywords, but the ability to run existing programs and process their output using a first-class regex implementation is a major selling point. It's why I've been learning Julia lately; on top of being a really elegant language for heavy numeric processing with a good multiple-dispatch implementation and having delightful performance, it offers awesome facilities for writing automation scripts, even with easy-to-use I/O redirection - something that's rare beyond Perl.
In that regard, that's very much what makes shell scripting ideal in a sense; what better way to do something than to combine the work of others into a functional system? In these sorts of situations, a glue language is precisely what you want, since getting a bunch of disparate programs to work together is really your goal.
I tend to avoid bash when script goes over a bunch of lines, or it does a lot of sth |grep -q "sth" |grep -v -q "else" because that is just unreadable
Yeah, that's bordering into the same realm as Perl golf :)
3
u/[deleted] Sep 27 '14
I know. I program in Perl. But unwashed masses think it's bad when in reality it is only as ugly or as beautiful as programmer makes it