Hacker News new | past | comments | ask | show | jobs | submit login

"A collection of pure POSIX sh alternatives to external processes."

"Ternary Tests"

Can anyone point to where in the POSIX standard ternary test are described. (NB. Pure POSIX sh is less featureful than Bash.) What am I missing.

https://web.archive.org/web/20201219013931/https://pubs.open...

Also these operators from C that the author includes. Is he suggesting these are available in POSIX sh.

Quoting from the Pure Sh Bible:

   += Plus-Equal (Increment a variable.)
   -= Minus-Equal (Decrement a variable.)
   *= Times-Equal (Multiply a variable.)
   /= Slash-Equal (Divide a variable.)
   %= Mod-Equal (Remainder of dividing a variable.)

   << Bitwise Left Shift
   <<= Left-Shift-Equal
   >> Bitwise Right Shift
   >>= Right-Shift-Equal
   & Bitwise AND
   &= Bitwise AND-Equal
   | Bitwise OR
   |= Bitwise OR-Equal
   ~ Bitwise NOT
   ^ Bitwise XOR
   ^= Bitwise XOR-Equal
One could probably learn from reading the POSIX standard, the Almquist shell source code and then experimenting. I also like reading other peoples' shell scripts, if they are good. Always something new to learn. Unfortunately this "Bible" did not teach me anything new.



Those operators are in "2.6.4 Arithmetic Expansion" in your linked doc. See the link to "Arithmetic Precision and Operations"[1].

[1]: https://web.archive.org/web/20201219013931/https://pubs.open...


Thank you. This helps. But does that mean a POSIX shell, or any other UNIX utility, must implement these operators. Using them in shell scripts makes the scripts non-portable, e.g., Almquist sh, NetBSD Almquist sh or Debian Almquist sh do not support them. Maybe the author of the "Pure POSIX Sh Bible" always runs Bash in --posix mode. Hence "Pure POSIX sh".


They've been in dash for a pretty long time. NetBSD has lagged behind a bit. http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=50...

This just means that you're going to have to find a better way to describe the level of backwards compatibility you're going for other than "POSIX compliance", because these do seem to be required in the standards.


Well it doesn't say that arithmetic expansion is "optional" or an "extension". Maybe those shells are conforming to an older version?


Seems like there are different interpretations by authors/maintainers of what is required versus what is optional.

As an ordinary user, I am most interested, perhaps mistakenly, in POSIX for a single reason: portability. (Whether portability is a goal of POSIX I am not sure. I have not done much research. Maybe it isn't.) As a user, I want to be able to write scripts on Linux than run on BSD and vice versa. Perhaps I have conflated portability with "POSIX compliance". However, as a practical matter, I would not use these operators in scripts that I wanted to be portable. When I have the motivation, I am working on a unenhanced port of NetBSD sh to Linux, i.e., without the Herbert Xu changes. Being lazy, so far I just added tab completion to dash so it feels more like NetBSD sh.

The "Bible" I would be interested in reading, if it exists. is the "Portable Sh Bible". (I am not a Bash user.) When I have a question I usually consult https://www.in-ulm.de/~mascheck/




Consider applying for YC's Summer 2025 batch! Applications are open till May 13

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: