Live data from Hacker News

Which is not Posix

hynek.me

81–90 of 97 posts

Re: Which is not Posix

#81

Earlier quoted context omitted.

> 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?

The main reason stated at the time was that dash was a much faster executable that would improve the performance on boot and all background tasks.

Re: Which is not Posix

#82
post #14
post #6

I do not understand this Debian 'which' kerfuffle, but seems a big argument over nothing. But for me, 'type' is my go to in scripts. And as a tcsh user, I never knew 'which' was a thing in Bourne shells until I checked a few minutes ago. I do not know when it appeared, but I thought in the 'old days' 'which' was specific just to [t]csh. Also, I never heard of 'command -v' until I saw it in LWN a few days ago :)

which is not a thing in bourne shells; it's a separate executable. If it were a builtin then there wouldn't be a kerfuffle; there are multiple implementations of "which" and Debian doesn't want to privilege one of them, but if Debian base scripts use one, then it must privilege one of them.

> and Debian doesn't want to privilege one of them

Any reason for that? Insisting on not choosing a preferred set of software seems like a really bad decision for a distro.

Re: Which is not Posix

#83
> Use command -v instead

Huh? That's a shell builtin, not an executable. That's next to useless.

> which is widespread but not standardized

What can possibly need standardization about "prints the full path to a command"???

> which in its barest form fails to handle builtins and aliases

Yes, because it's an executable, not a builtin. This means that it is usable from outside of a shell, which is quite a significant benefit. Additionally, there is no path to a builtin or alias - so it actually handles both how it says on the tin: it returns no path. Moreover, it's rarely useful to check for a builtin or alias from a non-interactive context.

> Just compare the arguments of the most common ones

I have literally never once had to pass a single argument to which, except the name of a command. At which point it has literally always given me back the path to that command (or nothing).

But, let's compare, shall we?

    - All 4 implementations support `which which`, with identical semantics
    - All 4 implementations support `which -a which`, with identical semantics
    - 2 implementations support no other options
    - 1 implementation has a -s flag for silent operation, which can be portably replaced by redirecting output.
    - 1 implementation has many more options... which appear to mostly be useful interactively. I'm not sure why this implementation is presented as "GNU"; the linked page clearly attributes it to a "Carlo Wood"
> For scripts, command -v is better, because it’s simpler and machine-readable.

I strongly doubt that `command -v` actually does what the author wants it to do. I can't imagine why you would want to end up with the string "alias ls='ls --color=auto'" in your variable when you were looking for "/bin/ls", as `which` would return.

Re: Which is not Posix

#84
post #26

Not sure why the outcome of "`which` is not POSIX" would be "essentially everybody should stop using `which` and start using `command -v`, which is poorly known, has different semantics, and is covered in relatively little introductory material" rather than "this is just another example of why POSIX has been nearly irrelevant for a long time now". systemd is not POSIX, either, but that's not taken as some justificati…

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'?). As for systemd, AFAIK system startup isn't covered by POSIX at all, so bsd init, sysv init and systemd are all equally not covered by POSIX. Which is fine, POSIX was never meant to cover every sing…

> incompatible

How?

Re: Which is not Posix

#85

Not sure why the outcome of "`which` is not POSIX" would be "essentially everybody should stop using `which` and start using `command -v`, which is poorly known, has different semantics, and is covered in relatively little introductory material" rather than "this is just another example of why POSIX has been nearly irrelevant for a long time now". systemd is not POSIX, either, but that's not taken as some justificati…

On Mac, with an alias I don't get the same answer from the two anyway: $ command -v emacs alias emacs='/Applications/Emacs.app/Contents/MacOS/Emacs -nw "$@"' $ which emacs /opt/local/bin/emacs

Correct, because they do two different things.

`which` is a standalone executable which searches the environment's PATH for the named command. It doesn't know about commands which aren't executables (i.e. builtins and aliases).

`command` is a shell builtin which tells you exactly what that shell in its current state would run.

Re: Which is not Posix

#86
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.

... huh? which is not a bash builtin.

Re: Which is not Posix

#87
post #53

Earlier quoted context omitted.

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.

POSIX does not specify /usr/bin/env, but the location is pretty much universal anyways.

Re: Which is not Posix

#88

Earlier quoted context omitted.

> 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?

Well Debian isn't some BDFL's project, different authors have different visions that sometimes don't agree with each other. With dash, the original advantages put forward were minimalism, higher speed, and POSIX compliance [1]. But that was a long time ago and when systemd came, the preference for dash may have changed for many Debian authors and maybe dash is just kept in Debian as a token of the past accomplishments.

[1] http://gondor.apana.org.au/~herbert/dash/

Re: Which is not Posix

#89
post #77

Not sure why the outcome of "`which` is not POSIX" would be "essentially everybody should stop using `which` and start using `command -v`, which is poorly known, has different semantics, and is covered in relatively little introductory material" rather than "this is just another example of why POSIX has been nearly irrelevant for a long time now". systemd is not POSIX, either, but that's not taken as some justificati…

Honest question, if POSIX is not relevant anymore, why haven't wee seen a user-friendly set of command line tools come out yet?

POSIX isn't very relevant, but the set of basic Linux tools with generally expected features and behaviour is. The difference is that the latter evolves. For example, when GNU tools appeared, people started to prefer them to POSIX tools, because the GNU tools had useful extensions. POSIX never catched up.

So we have seen more friendlier set of tools than POSIX would force on us, but it was evolution, not revolution. Why, maybe because people see value in continuity and acquired knowledge and don't want to start using obscure new tools like ag or exa, even if they could be superior.

Post reply on HN