Hacker News new | ask | show | jobs
by yjftsjthsd-h 1365 days ago
> Serious question, why should I care about portability to Apple in shell scripts?

It depends on your target audience, of course, but Darwin is one of the major current OSs and wanting to support it is reasonable.

> Why not make all your shell scripts #!/bin/bash and anything where that doesn't work is trying to be a second class citizen[1] in unix and so maybe let them? Or tell users to install Bash - which they can probably do if they're using shell scripts..?

Well, for starters AFAIK /bin/bash on Darwin will give you bash 3.2, which is a bit old and feature-poor. Of course you can (and perhaps even should) simply install a new version but then it won't be at /bin/bash, it'll be under /usr/local or /opt or whatever. And BASH isn't POSIX so I'd personally argue that trying to force it makes your stuff the "second class citizen in unix".

Honestly I'm not sure what position you're trying to argue. "Ignore the second biggest desktop OS because they don't ship the latest version of the non-standard scripting language I like"?

2 comments

>"Ignore the second biggest desktop OS because they don't ship the latest version of the non-standard scripting language I like"?

There's nothing wrong with that position. Bash is not a "non-standard scripting language people like", it is the de-facto standard on Linux (heck, it was the first program Torvalds ever run on Linux) and the most widespread implementation of POSIX shell in the world. If Apple chosed tivoization[1] over freedom, so I can choose the #!/bin/bash shebang.

[1] https://en.m.wikipedia.org/wiki/Tivoization

> Bash is not a "non-standard scripting language people like", it is the de-facto standard on Linux (heck, it was the first program Torvalds ever run on Linux)

That sounds like the definition of not being standardized. BASH is the most common shell implementation on GNU systems (no, not Linux; Alpine is a Linux, and so is Android), but that doesn't make it a standard, only common. It's like claiming that nobody should care about anything but Chrome because it's "the de-facto standard".

> and the most widespread implementation of POSIX shell in the world.

BASH can run POSIX sh scripts, but POSIX sh can't run BASH scripts. If you're only using POSIX features, then it's not a problem, but if you're only using POSIX features we wouldn't be having this argument.

> If Apple chosed tivoization[1] over freedom, so I can choose the #!/bin/bash shebang.

Could I at least talk you into using `#!/usr/bin/env bash` so your scripts will work on a wider slice of the Linux universe? Even on Linux distros that exact path isn't a given (guix and nix send their regards), and you're completely breaking compatibility with the BSDs and illumos distros.

> Could I at least talk you into using `#!/usr/bin/env bash` so your scripts will work on a wider slice of the Linux universe? Even on Linux distros that exact path isn't a given (guix and nix send their regards), and you're completely breaking compatibility with the BSDs and illumos distros.

You're also breaking compatibility with newer versions of bash on macOS that almost definitely wouldn't be installed at /bin/bash. I use 5.2 from brew.

bash isnt posix???

if bash isnt posix then wth is? if you told me "British English isnt actually English" I'd be less surprised than bash and posix.

> bash isnt posix???

No

> if bash isnt posix then wth is?

POSIX sh (https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V...).

POSIX defines a shell that's not completely compatible with Bash. IIRC Ubuntu's `sh` command actually runs bash in a special "POSIX-compatible" mode that's really bare-bones.