4 ms·
Why write new bash scripts in this day and age...
by nialv7 9y ago
Why write new bash scripts in this day and age...
- riquito 9y agoThey are fast, ubiquitous, 0-dependencies, short, espressive... most of the time. The fact is that we don't have anything better to glue commands together (afaik).
- virtualized 9y ago"Glueing commands together" is called programming. That's what programming languages are for. Bash etc are just really bad programming languages that lure you into a trap of unnecessary complexity with their superstitial expressiveness for the happy path in short programs, when you don't need anything besides the built-ins. Decades of ubiquitous UNIX crap tricked you into believing that bash's properties are advantages rather that disadvantages. Sure, you can "glue together" a few commands quickly, but only at the price of horrible edge cases and hours of StackOverflowing for doing the simplest of things.
- logicallee 9y ago>but only at the price of horrible edge cases and hours of StackOverflowing for doing the simplest of things. Or seconds, after you learn the search term "Perl one-liner" and add it to your queries for all your edge cases. Start thinking of perl -we as a Bash built-in function. Suddenly edge cases go from hours to your typing speed into Google. Don't forget to leave a comment with a link to where you found the solution, what it does according to that site, and an apology for the unreadable line noise. If you make changes to what you copy and paste, explain your changes in a comment. (Just in case it sounds sarcastic or ironical, this comment is serious and how I really work. I am really glad for my comments whenever I revisit old scripts.)
- Slackwise 9y ago> 0-dependencies Actually, quite the opposite. All that shell scripts do is glue together other programs they depend on. That makes them not portable. You can't just move a bash script from Linux to macOS because it uses ancient pre-GPLv3 versions of bash and all the other GNU utils.
- jstimpfle 9y agoJust use POSIX-compatible sh instead of bash. It's also not hard to use mostly POSIX-compatible commands (grep, sed, cat, cp, mkdir ...). For scripts where you need something unstandardized, say, imagemagick, you would wind up with up with a dependency in most other languages as well.
- zwischenzug 9y agoThis is not so unreasonable a question, but the answer is simple: because it's ubiquitous, fairly standardised, and well supported. Also, other languages suck at doing small things quickly and simply. Try rewriting a shell script in go with little experience and see how long it takes.
- kbart 9y agoIt's not in fashion anymore or what? If it gets the job done, that's all I need.
- chedabob 9y agoYeah, in the OP why wouldn't you make the same LDAP query using any of the numerous libraries available for other languages? I'll take the tiniest little bit of complexity of having to make sure Python and PiP are installed on my environment, over a Bash script falling apart at the seams from an edge case.
- PapaSpaceDelta 9y agoOne reason is that any System Administrator can be expected to be able to understand and maintain Bash scripts. I recently built a fairly complex system entirely in Bash, not because it was the "best" language for the job (it would have been much easier to do in Ruby or Python), but because the client didn't have any permanent staff that could maintain Ruby or Python scripts. As a contractor, one of the major factors in the technical decisions I make is: how supportable is this technology for the client, once I have left? Of course the answer to that question will vary on a case by case basis, but Bash is usually a good lowest common denominator in a Linux environment.
- Sean1708 9y agoBecause Bash is horrible, but occasionally it's still the best tool for the job.