Hacker News new | ask | show | jobs
by stephenr 3176 days ago
Sure, I understand this was definitely a problem for a long time, it just seemed odd to post it now (I initially thought maybe it was a new submission of an old blog post).

FYI Your shell script is still not really valid. You should either fix the bash-isms (best option) or target bash specifically in the shebang line.

ShellCheck (http://www.shellcheck.net) should help with making it sh (posix shell) compatible.

Edit: probably more friendly.

1 comments

alright will have a closer look, I use zsh so it can be harder to spot such problems.
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.