Hacker News new | ask | show | jobs
by gaigalas 30 days ago
Most shell families precede the spec. Both bash and ksh had features at the time the spec was written that are not in it. It's weird.

My main point is that following the spec doesn't guarantee shell scripts will be portable, which is a common misconception.

1 comments

> My main point is that following the spec doesn't guarantee shell scripts will be portable, which is a common misconception.

That feels like a failure in the spec. Your example illustrates it: echo has unspecified behavior that literally prevents it from being portable.

Is it possible portability is just not a feature of posix?

POSIX specifies a common subset of functionality of several different shells (and C libraries) that existed when it was created, and that any compliant shell (or C library) will share. Some functions like `echo` are guaranteed to be present but don't have fully-specified behavior, because the shells that POSIX was created to be the common functional subset of had different behaviors when POSIX was created.

POSIX doesn't guarantee portability. POSIX only guarantees that the things it specifies will work in a POSIX-compliant environment. POSIX makes no guarantees about portability to non-POSIX-compliant environments like Windows' shells or MSVC, the Fish shell, etc. POSIX makes no guarantees about the things it doesn't specify.

I honestly don't know! What I know is that there is an intersection of features that work with polyfills and tweaks in all shells. That intersection has a lot of the spec, but also has a lot that is not specified anywhere.

I started to build something here 12 years ago: https://github.com/Mosai/workshop. Then here 2 years ago: https://github.com/alganet/coral

Now I'm attacking it from another angle, trying to document what I learned methodically and share the tools I made for me with everyone else.