4 ms·
Well, shell scripts are extremely convenient. It's easy to write very simple ones since they're a natural extension of shell usage. So it's really easy to go f
by oblio 10y ago
Well, shell scripts are extremely convenient. It's easy to write very simple ones since they're a natural extension of shell usage.
So it's really easy to go from
$ command1
$ command2
to:
#!/bin/bash
command1
command2
As a result, everybody "likes" bash scripts since they're so easy to write, initially.
And these shell scripts will work well in 80% of situations and you can get them to 90-95% just by sprinkling a few ifs around.
Once thes script becomes longer and more complex and you want to make them easier to read and DRYer, that's when the pain begins. Or when you need to handle a bit of logic which would be trivial to do with better data structures such as arrays or dictionaries or sets...
You can work around these issues, of course, but almost every workaround is either ugly or a hack (as someone was joking, "elegant hacks" for older Unix hackers, "gross hacks" for younger ones :) ).
- growse 10y agoI agree - in my experience bash is extraordinarily easy to write the first time. It becomes a nightmare to maintain, because most people aren't actually that familiar with how bash error handling, flow logic etc. actually works. It's bad because it fails in surprising, non-conventional ways.
- yjftsjthsd-h 10y ago> better data structures such as arrays or dictionaries or sets POSIX sh doesn't have these, but BASH actually does have arrays, and even dicts (see https://stackoverflow.com/questions/688849/associative-arrays-in-shell-scripts/691157#691157 https://stackoverflow.com/questions/688849/associative-array...)
- nerdponx 10y agoAnd if you're willing to spend time learning Zsh, you have a surprisingly reliable and expressive language. Or you could just learn Perl...
- kps 10y agoOr ksh, which bash was a half-assed imitation of. Or if you're just stringing commands together, traditional simpler Posix sh (note: 'bash --posix' isn't).