News for hackers. Stuff that matters.
Re:A few facts about POSIX by BoingBoomTschak on Tuesday April 30, 2024 @07:48AM (#40209952)
>such as MacOS, that are fully compliant with the POSIX standard

Until you have to gets your hands dirty and find small and bigger faults everywhere. For example, /bin/sh defaults to their ancient (last GPL2 release) bash that doesn't work properly in these two parameter expansion cases:

  $ cat test.sh
  var=
  echo "${var+{\}}"
  cat <<EOF
  ${var+\"z\"}
  EOF
  $ /bin/sh test.sh
  {\}z
  \"z\"
  $ /bin/dash test.sh
  {}
  "z"
Second one bit me quite badly when doing heredocs to generate JSON.
Re:A few facts about POSIX by Karellen on Tuesday April 30, 2024 @08:17AM (#40210198)
Program^WCompliance testing can be a very effective way to show the presence of bugs, but it is hopelessly inadequate for showing their absence.

-- Edsger Dijkstra (ish)

Re:A few facts about POSIX by eadmund on Tuesday April 30, 2024 @08:50AM (#40210486)
It really says something about how much Apple cares about restricting its users’ freedom versus implementing functionality for those users that in 17 years they haven’t been bothered to either write their own /bin/sh, fix the ca. 2007 bash they do ship or just ship a newer, GPLv3 bash.

And it really says something about how important it is to license one’s software under GPLv3 or similar!

Re:A few facts about POSIX by icedchai on Tuesday April 30, 2024 @09:12AM (#40210639)
They basically want you to use zsh... It's been the default shell for a while. If you want a newer version of bash, install it yourself with brew or macports.
Re:A few facts about POSIX by BoingBoomTschak on Tuesday April 30, 2024 @09:14AM (#40210650)
What's even more comical is that they also ship dash, as shown in my example! But the reason why is obvious: people using a /bin/sh shebang with bash features.

So I understand, but patching bash to fix the --posix mode should still be done.

Re:A few facts about POSIX by paulddraper on Tuesday April 30, 2024 @11:05AM (#40211787)
I think it's best to consider MacOS not having bash by default.

(The OS shell of choice being zsh.)

Re:A few facts about POSIX by glhaynes on Tuesday April 30, 2024 @02:01PM (#40214036)
That might hold more weight for me if it weren't the easiest thing in the world to install bash! Like literally `brew install bash` will do it, right? That way I'm not reliant on Apple at all, which seems optimal when we're talking about features they don't build and that aren't their focus. I'm very happy to let Apple do the things they're good at and the community do the things they're good at.
Re:A few facts about POSIX by BoingBoomTschak on Tuesday April 30, 2024 @07:07PM (#40217569)
Scripts using #!/bin/sh instead of #!/usr/bin/env (ba)sh won't use your shiny new shell. Including scripts deep inside the build system of misc. software that you won't modify.

The only way is to set their strange /etc/private symlink (cf sh(1)) to change what /bin/sh execs, and to do it again after each update which resets it.

Re:A few facts about POSIX by vorakl on Tuesday April 30, 2024 @08:47PM (#40218284)
I wonder what is the origin of this "/bin/sh" and why it's often assumed that sh is in /bin by default. The standard is pretty clear about that:

"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."

"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)."

Ref: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/s...

So, apparently on systems, where sh resides in /bin, "getconf CONF" will return /bin . However, this is not always the case. For example, on my Fedora Linux it is /usr/bin

  $ getconf PATH
  /usr/bin
  $ ls -l /usr/bin/sh
  lrwxrwxrwx. 1 root root 4 Jan  2  2023 /usr/bin/sh -> bash
  $ ls -l /bin/sh
  lrwxrwxrwx. 1 root root 4 Jan  2  2023 /bin/sh -> bash
  $ ls -ld /bin
  lrwxrwxrwx. 1 root root 7 Aug  9  2022 /bin -> usr/bin
Re:A few facts about POSIX by BoingBoomTschak on Tuesday April 30, 2024 @10:38PM (#40218941)
Probably the natural consequence of shebang limitations and the "chicken and egg problem" of env(1) that isn't always in /usr/bin.

If only we could write #!sh to do a PATH lookup...

Thanks for finding the exact POSIX section describing its own failings!

On Gentoo (with the recent merged-usr profile), getconf PATH returns "/bin:/usr/bin", heh.

Re:A few facts about POSIX by foldr on Tuesday April 30, 2024 @09:13AM (#40210642)
Apple added /bin/dash in Catalina, and the intention is probably to eventually to use dash as the implementation of sh: https://scriptingosx.com/2020/06/about-bash-zsh-sh-and-dash-....

As for why they haven't done it yet, I'd guess it's just to preserve backward compatibility with old scripts that rely on quirks of bash's sh compatibility mode.

Re:A few facts about POSIX by lelandfe on Tuesday April 30, 2024 @10:06AM (#40211084)
Oh they added it to recovery too. Interesting.
Re:A few facts about POSIX by kergonath on Tuesday April 30, 2024 @11:10AM (#40211856)
> Until you have to gets your hands dirty and find small and bigger faults everywhere. For example, /bin/sh defaults to their ancient

It’s irrelevant. Neither POSIX nor the UNIX certification (or being a descendant of the UNIXes of old like the BSDs) requires a recent GNU userland (which is, as the name implies, not UNIX).

Re:A few facts about POSIX by Karellen on Tuesday April 30, 2024 @11:24AM (#40212034)
> > > such as MacOS, that are fully compliant with the POSIX standard

> > Until you have to gets your hands dirty and find small and bigger faults everywhere. For example, /bin/sh [...] doesn't work properly in these two parameter expansion cases:

> It’s irrelevant. Neither POSIX nor the UNIX certification [...] requires a recent GNU userland

Is it irrelevant?

If an implementation passes the conformance test suite, but is buggy according to the text of the spec in a way that is not caught by the test suite, can one really say it's "fully compliant with the POSIX standard"?

Is it the test suite that's the final arbiter of the POSIX standard, or is the text of the spec? Because I thought that the point of having a written spec, ratified by a standards body, is that the text of the spec defines what the spec is. It is the text of the spec that is submitted to the standards body, after all, not the test suite.

Re:A few facts about POSIX by BoingBoomTschak on Tuesday April 30, 2024 @07:03PM (#40217546)
I said /bin/sh, not /bin/bash.
Re:A few facts about POSIX by postmodest on Tuesday April 30, 2024 @11:23AM (#40212018)
They dropped any utility that switched to GPLv3 because of v3's infectious patent clause that would've put their patent portfolio in danger.
Re:A few facts about POSIX by TheFuzzball on Wednesday May 01, 2024 @08:58AM (#40222521)
The default shell on macOS has been zsh for over 4 years now, and they keep it up-to-date.