Live data from Hacker News

Which is not Posix

hynek.me

51–60 of 97 posts

Re: Which is not Posix

#51
post #40
post #29

Linux from Scratch has a very tiny implementation suitable for all systems that have bash installed: #!/bin/bash type -pa "$@" | head -n 1 ; exit ${PIPESTATUS[0]} Just save it as which, chmod +x and add to path. https://www.linuxfromscratch.org/blfs/view/svn/general/which...

Not all systems have bash as /bin/bash. A shebang line of '#!/usr/bin/env bash' would be even more portable.

I like bash 4+ for associative arrays, and use it on macOS. But macOS is still v3 by default (for /bin/bash).

I think `/usr/bin/env bash` is a great shebang, for the record, but I'm not totally convinced that it's more portable than `/bin/bash`. Can you explain what makes it actually more portable? In absence of that, you might actually expect `/bin/bash` to be more portable, as at least you can more likely make assumptions based on the OS.

Re: Which is not Posix

#52
post #50
post #28

Earlier quoted context omitted.

Any that more than 10 people use?

The Fedora base image does not include which. The base image is what's used in the standard OCI Fedora container, some Flatpak work, and some other things. Arch also doesn't include "which", nor do some arch-based distros.

Arch uses zsh in the Installation Medium and bash as default shell of the code System, both have which as a builtin function.

Re: Which is not Posix

#53
post #40

Earlier quoted context omitted.

Not all systems have bash as /bin/bash. A shebang line of '#!/usr/bin/env bash' would be even more portable.

I like bash 4+ for associative arrays, and use it on macOS. But macOS is still v3 by default (for /bin/bash). I think `/usr/bin/env bash` is a great shebang, for the record, but I'm not totally convinced that it's more portable than `/bin/bash`. Can you explain what makes it actually more portable? In absence of that, you might actually expect `/bin/bash` to be more portable, as at least you can more likely make assu…

>Can you explain what makes it actually more portable?

POSIX. The NixOS machine I'm typing this on has /usr/bin/env but not /bin/bash.

Re: Which is not Posix

#54
post #39

So, is there a distribution that is POSIX, and nothing else, both in commands and API? Would be fun to have (in a VM; I guess it would be too annoying to use as one’s main system), for compatibility testing.

Not a Linux distribution, but the Unix implementation in z/OS, IBM's mainframe operating system, is painfully POSIX-compliant.

Re: Which is not Posix

#55
post #36

Earlier quoted context omitted.

> As the Debian brouahaha pointed out, there are multiple incompatible implementations of which, so it's unclear which one (ha ha) POSIX should standardize on (and is it politically realistic to anoint one as the 'winner'?). It's meaningless that there's no clear version that POSIX should standardize on – GNU `which` is the de facto standard on Linux. Debian is hardly going to ship FreeBSD's `which`, as even the disc…

> GNU `which` is the de facto standard on Linux Well, no, even on Linux there's no de facto standard. Fedora/RHEL use GNU which, but Debian-derived distros use the debianutils which, which is not the same as GNU which. > POSIX doesn't cover init, but it does cover many other system calls and behaviours that systemd explicitly rejects Interesting. Can you be a bit more specific? What in POSIX does systemd explicitly r…

> Well, no, even on Linux there's no de facto standard. Fedora/RHEL use GNU which, but Debian-derived distros use the debianutils which, which is not the same as GNU which.

Honest question, is any of this relevant? It's a mystery to me why anyone would care as long as it gets the job done. Anyone wanting something else can go ahead and use it. Put differently: it would make no difference to anyone currently using command -v. If the Debian devs have a time machine, they can go back to the start and change the course of history. Otherwise none of the discussion around this issue makes sense.

Re: Which is not Posix

#56
post #52
post #50

Earlier quoted context omitted.

The Fedora base image does not include which. The base image is what's used in the standard OCI Fedora container, some Flatpak work, and some other things. Arch also doesn't include "which", nor do some arch-based distros.

Arch uses zsh in the Installation Medium and bash as default shell of the code System, both have which as a builtin function.

Except the behavior of the builtin is not the same as the behavior of the program, and Arch's base package doesn't include the which command.

Re: Which is not Posix

#57
post #36

Earlier quoted context omitted.

> GNU `which` is the de facto standard on Linux Well, no, even on Linux there's no de facto standard. Fedora/RHEL use GNU which, but Debian-derived distros use the debianutils which, which is not the same as GNU which. > POSIX doesn't cover init, but it does cover many other system calls and behaviours that systemd explicitly rejects Interesting. Can you be a bit more specific? What in POSIX does systemd explicitly r…

> Interesting. Can you be a bit more specific? What in POSIX does systemd explicitly reject? And might there be a reason for that? The project specifically rejects "caring about POSIX" in its entirety. Poettering has discussed this at length[1]. I'm not criticizing systemd here, I'm merely pointing out that Debian is already perfectly fine with shipping non-portable, aPOSIX or even anti-POSIX software by default (whi…

If Debian is perfectly fine with anti-POSIX, why go to the effort of making and switching to dash over bash? One of the impetuses for that project was bash’s inability to confirm to posix even when launched in posix mode. What’s that about?

Re: Which is not Posix

#59
post #40

Earlier quoted context omitted.

Not all systems have bash as /bin/bash. A shebang line of '#!/usr/bin/env bash' would be even more portable.

Not all systems have env has /usr/bin/env.

The presence of the env command is required by POSIX, and /usr/bin/env is the closest thing we have to a standard path for it.

Re: Which is not Posix

#60
post #42
post #36

Earlier quoted context omitted.

> GNU `which` is the de facto standard on Linux Well, no, even on Linux there's no de facto standard. Fedora/RHEL use GNU which, but Debian-derived distros use the debianutils which, which is not the same as GNU which. > POSIX doesn't cover init, but it does cover many other system calls and behaviours that systemd explicitly rejects Interesting. Can you be a bit more specific? What in POSIX does systemd explicitly r…

The one that comes to my mind is crontab, [which can be] replaced by timer units. These are all the POSIX standardized commands: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ It's also interesting that POSIX specified a job queue environment that nobody seems to use (entry with the qsub command), separate from the simple job system that originated in Bill Joy's C shell. The systemd oneshot service modif…

I use qsub daily with sun grid engine. Other derivatives of grid engine and I believe SLURM also implement qsub.
Post reply on HN