logoalt Hacker News

POSIX Is Not a Shell

45 pointsby gaigalasyesterday at 8:39 PM34 commentsview on HN

Comments

JdeBPtoday at 1:04 AM

Stéphane Chazelas would agree,

* https://unix.stackexchange.com/a/496642/5132

because the problem here is educating people with slipshod ideas about 'sh' being 'the POSIX shell' or (worse) 'the Bourne shell'. Both M. Chazelas and M. Gaigalas are making the point that 'sh' is a language that one aims to write in, not one of the many programs that sort of, sometimes, if invoked in the right way, implement that language; and a subordinate point that people are generally very poor about doing that when yet they insist that they are writing 'POSIX shell script'.

Fun facts: Standardization led by existing practice is not a simple process.

* https://unix.stackexchange.com/a/493743/5132

POSIX/SUS standardization is not a static thing. The long discussed thorny issue of echo has now subtly changed from all of those explanations given about it over the years, because in 2024 the standard was changed.

* https://pubs.opengroup.org/onlinepubs/9799919799/utilities/e...

M. Chazelas's own quite famous 2013 StackExchange answer on the subject has not yet been updated with the change that now incorporates -e and -E into the rule. Amusingly, it was M. Chazelas that raised defect 1222 that caused this change.

* https://unix.stackexchange.com/a/65819/5132

* https://www.austingroupbugs.net/view.php?id=1222

show 1 reply
Muhammad523yesterday at 10:47 PM

This post is nice: the writer first explains a problem, using a simple example. In the next section, they reflect a bit about the problem, and then they casually mention two tools they built. In my opinion, this is amazing: you sponsor you project, while also making the problem it solves clear: use their tool to test how portable your code is

show 1 reply
echoangleyesterday at 10:23 PM

Pretty bad argument. If it’s not defined by POSIX, it’s not POSIX compatible if you rely on a specific behavior.

If you only use defined behavior and it works, it is compatible.

It’s like saying C99 isn’t a compiler. True, but you can still write C99 code, right?

show 1 reply
chasiltoday at 2:15 AM

The author has neglected the pdksh family of shells which includes all of Android, so this is a sizable oversight.

This would include the MirBSD mksh, and oksh from OpenBSD.

They are much smaller than ksh93 and bash, and I would suggest that their syntax extensions be given preference, as they originally represented ksh88 (from which the POSIX shell standard was derived).

show 1 reply
qudattoday at 1:30 AM

This is quite a timely post compared to: https://bower.sh/posix-shell-is-all-you-need

This post was thought provoking, I wonder, is the hidden argument here that the posix spec for a shell is not well specified if there is so much variance between the implementations?

Or is the fundamental issue simply a matter of history? Both?

show 2 replies
XYen0ntoday at 2:56 AM

Usually I prefer to use `#!/usr/bin/env bash`.

kevin_thibedeautoday at 1:28 AM

Solaris most definitely has a POSIX shell at /usr/xpg4/bin/sh which behaves differently than OG Bourne at /bin/sh.

show 1 reply
croemertoday at 1:30 AM

Inconsistent: claims /bin/sh on Alpine is dash in one paragraph, BusyBox ash in another.

Smells a lot of AI writing.

show 1 reply
sdovan1yesterday at 11:48 PM

If your environment is POSIX, testing scripts with tool written in POSIX shell, like shellspec[1], might also be a choice.

[1] https://shellspec.info/

jmclnxyesterday at 11:24 PM

Will not build without docker, so I am out of luck. This tells me this is not portable, even to some Linuxes.

show 2 replies
paulddrapertoday at 1:00 AM

> When someone says "write it in POSIX shell for portability," they mean well.

> POSIX is a specification. Not a program. The thing that actually runs your script is bash, dash, ash, ksh, yash, or one of a dozen others.

“When someone says ‘write it in ECMAScript,’ they mean well.

“ECMAScript is specification. Not a program. The thing that actually runs your script is Node.js, Bun, Deno, Rhino, or one of a dozen others.”

See how silly that sounds?

show 1 reply