Hacker News new | ask | show | jobs
by dhruvasagar 3172 days ago
alright will have a closer look, I use zsh so it can be harder to spot such problems.
1 comments

So, this isn't really related to which interactive shell you use. The script is executed in the shell named by the shebang (#!/bin/sh) line.

/bin/sh though, is a bit of a "special" case - back in the day, it would have been the Bourne Shell (as distinct from Bash, which is the Bourne Again Shell).

These days, it depends on your platform - macOS uses Bash to provide /bin/sh, Debian/etc use Dash, and I believe the BSD's use Almquist (ash).

Dash and Ash (which Dash is a 'descendant' of) are pretty close to POSIX compliant, but 'Bash as /bin/sh', while being 'more strict', doesn't drop support for all Bash-isms, so your script probably works fine on macOS but will fail miserably on a recent Linux or BSD.

Edit: FYI, if anyone wants to properly test portable (i.e. POSIX /bin/sh compatible) shell scripts on macOS, Dash is pretty simple to install from source. I'd still suggest using VM's to test in a variety of shells (Ash, Dash, Posh would give pretty decent coverage) but for quick tests, native Dash will be more representative than Bash.