News for hackers. Stuff that matters.
Re:Bash 5.0 released by JeremyBanks on Monday January 07, 2019 @09:42PM (#18852641)
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.

Re:Bash 5.0 released by nwatson on Monday January 07, 2019 @09:53PM (#18852696)
I recommend Greg's Bash Wiki ... 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.

Re:Bash 5.0 released by dorfsmay on Monday January 07, 2019 @11:05PM (#18853050)
It 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.
Re:Bash 5.0 released by int_19h on Tuesday January 08, 2019 @12:44AM (#18853514)
BSDs 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.
Re:Bash 5.0 released by AnIdiotOnTheNet on Monday January 07, 2019 @10:56PM (#18853014)
Or you just bundle your application and its dependencies into a single folder for each OS and distribute it.
Re:Bash 5.0 released by platinumrad on Monday January 07, 2019 @10:25PM (#18852855)
>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.

Re:Bash 5.0 released by JeremyBanks on Tuesday January 08, 2019 @06:23PM (#18860803)
It 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.

Re:Bash 5.0 released by mohaine on Monday January 07, 2019 @09:48PM (#18852669)
As they say, bash is just good enough not to get replaced.
Re:Bash 5.0 released by bpchaps on Monday January 07, 2019 @10:30PM (#18852881)
Sure 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.

Re:Bash 5.0 released by cheez on Monday January 07, 2019 @10:51PM (#18852987)
I just use set -e at the top of the script
Re:Bash 5.0 released by JeremyBanks on Monday January 07, 2019 @11:44PM (#18853213)
That's a good idea, but it's not a complete solution. See http://mywiki.wooledge.org/BashFAQ/105
Re:Bash 5.0 released by cheez on Tuesday January 08, 2019 @08:18PM (#18861481)
Nice. But I use C++ so I'm used to shooting off my own foot.