3 ms·
It can't be done. If you want to write reliable code, and actually notice all of the possible error conditions instead of silently ignoring them, your code need
by JeremyBanks 8y ago
It can't be done. If you want to write reliable code, and actually notice all of the possible error conditions instead of silently ignoring them, your code needs to get more verbose and complicated than it would be to just use a more capable tool like Python or Node, and it still won't be as reliable.
If you have more logic than a couple of string comparisons, Bash is not the right tool for the job.
- mohaine 8y agoAs they say, bash is just good enough not to get replaced.
- nwatson 8y agoI recommend Greg's Bash Wiki ... https://mywiki.wooledge.org/BashGuide https://mywiki.wooledge.org/BashGuide. See general notes, then at the bottom of the page are many links to additional considerations. Like others say, "bash" is a hard tool to get right (and I'm not saying I do it right either, necessarily, but Greg's Wiki was real helpful!). I'm building a hybrid bash/python3 environment now (something I'll hopefully open-source at some point), and bash is just the "glue" to get things set up so most aspects of development can funnel through to python3 + other tools. But ... things that make bash real useful: * it's available everywhere (even in Windows with Ubuntu-18.04/WSL subsystem) * it can bootstrap everything else you need * it can wrap, in bash functions, aliases, and "variables" (parameters), the real functionality you want to expose ... the guts can be written in python3 or other tools Without a good bash bootstrap script you end up writing 10 pages of arcane directions for multiple platforms telling people to download 10 packages and 4 pieces of software per platform, and nobody will have consistent reproducible environments. EDIT: I think there's a revised version of Greg's Bash Wiki in the works.
- AnIdiotOnTheNet 8y agoOr you just bundle your application and its dependencies into a single folder for each OS and distribute it.
- dorfsmay 8y agoIt is availbale, almost, everywhere but be careful with the version, different Linux diatros are at different versions, the last time I used OSX it was stuck on a very old version, and I expect the different BSD OSes to run fairly new versions.
- int_19h 8y agoBSDs don't ship Bash as part of the base system - you have to install it from packages or ports. And that one is the most recent that the maintainer bothered to package. E.g. FreeBSD is on 4.4.23 right now, which actually appears to be newer than e.g. Debian unstable.
- platinumrad 8y ago>Python or Node Python, sure, but replacing Bash with Node just seems like replacing a language crippled by its need to be backward compatible with (Bourne) sh with a language crippled by its need to be backward compatible with what Brandon Eich came up with in two weeks in 1995.
- JeremyBanks 8y agoIt wouldn't be my first choice either, but modern JavaScript isn't backwards-compatible, it is at least possible to write reliable and robust code if you take some care and know what options to enable, and it's mostly consistent across platforms. Last month, I spent a week trying to handle all of the possible error conditions in an overgrown bash script. It was immeasurably worse. Python is the more direct substitute, though: it's built-in to almost every platform, and the Python 3 stagnation has even given us a consistent version: 2.7.
- bpchaps 8y agoSure it can. Treat it as a functional and immutable language, and you can go pretty far with it, pretty safely. You're forgetting that bash really just calls other code. So you can combine two language's stdin/out functionality (eg, Python or Node) to pair code together. Sure, it won't be fast, but it can do quick wonders as an ad hoc data pipeline.
- cheez 8y agoI just use set -e at the top of the script
- JeremyBanks 8y agoThat's a good idea, but it's not a complete solution. See http://mywiki.wooledge.org/BashFAQ/105 http://mywiki.wooledge.org/BashFAQ/105
- cheez 8y agoNice. But I use C++ so I'm used to shooting off my own foot.