by Karellen · 4y ago · 0 comments
But... "the shell and standard utilities and files that are in known locations and standard capabilities and various other things" are also specified by POSIX.
(Historically, they were the "POSIX.2" standard, and the libc/syscall library functions were in the "POSIX.1" standard, but since 1998 when POSIX became the ratification of Single Unix Specification version 2-and-later, they're all just in "POSIX".)
So... yes?
> Unless you intend for your program to be narrowly and specifically portable to POSIX or an even more minimal standard, it is not a bug for it to rely on portions of the broader, de facto Unix API. It's not even necessarily a bug to rely on APIs that are only there on some Unixes (for example Linux and FreeBSD),
Why would any of those things be considered a "bug"?
> for example, can you implement a compatible and fully capable Bourne shell using only public Unix kernel APIs, or at most public C library APIs?
What other APIs does the author think that Bourne shell writers used?
I feel like I'm missing some broader context for this post.
As stated in the sentence, it would be considered a bug if the program was intended to portable.
Why would it be a "feature" to write non-portable programs that only compile on some but not all UNIX-like operating systems.
I can think of some reasons but none of them benefit end users who like the freedom to use a variety of UNIX-like operating systems.
Because you want features that require platform-specific APIs and two Unix-like systems (Linux and Darwin) have 99.9% of the marketshare among your audience?
With this attitude Docker wouldn't have happened, because we'd still be bickering about a standardized API for container primitives, because someone wants to run containers on the Lites kernel on a PA-RISC machine.
Unfortunately, it doesn't specify those known locations. It explicitly declines specifying that /bin/sh exists.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/s... says:
> Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in.
and it doesn't specify the location of getconf either, so you have a chicken-and-egg problem where you need the standard $PATH to find getconf to get the standard $PATH.
# command -p getconf PATH
If you're writing C code of course you just use the library function.
Another interesting snippet from your link:
"Furthermore, on systems that support executable scripts (the "#!" construct), it is recommended that applications using executable scripts install them using getconf PATH to determine the shell pathname and update the "#!" script appropriately as it is being installed (for example, with sed)."
So there could be systems which does not support shebang yet claiming to be POSIX?
Huh. TIL. I've worked with POSIX for a couple of decades now, and I was sure that it required `/bin/sh` to be a valid path to the shell.
Thanks!
Incidentally, a ton of GNU utilities aren't POSIX unless you set the POSIXLY_CORRECT environment variable...
Ohhh, that's how Windows could be POSIX-compliant back in the 90s while not appearing like it at all. Thanks.