Which is not Posix
hynek.me
Which is not Posix
1–10 of 97 posts
Re: Which is not Posix
#2Re: Which is not Posix
#3 $ command -v command
command
vs $ which command
/usr/bin/commandRe: Which is not Posix
#4macOS Catalina 10.15.7 $ command -v command command vs $ which command /usr/bin/command
If you just run `command`, you are running the builtin function and not the /usr/bin/command file.
Try running `command -V command` and `command -V /usr/bin/command`
Re: Which is not Posix
#5Yeah, no thanks, I'm going to keep using `which`, and distributions are going to support it, no matter how "standard" `command -v` is. The only reason we're talking about this is that it's so noteworthy that any distro would seriously suggest people avoid `which`, which is the de facto standard.
C:\Users\luser>busybox64 sh
~ $ command -v ssh
C:/WINDOWS/System32/OpenSSH/ssh.exe
~ $ which ssh
C:/WINDOWS/System32/OpenSSH/ssh.exe
~ $ exitRe: Which is not Posix
#6But 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 :)
Re: Which is not Posix
#7macOS Catalina 10.15.7 $ command -v command command vs $ which command /usr/bin/command
command is a bash builtin. /usr/bin/command is a bash script that calls into the builtin command. If you just run `command`, you are running the builtin function and not the /usr/bin/command file. Try running `command -V command` and `command -V /usr/bin/command`
Re: Which is not Posix
#8systemd is not POSIX, either, but that's not taken as some justification for removing it from Debian – this whole drama is just pointless pedantry over something precisely because it is so low stakes.
Re: Which is not Posix
#9Re: Which is not Posix
#10edit: Well apparently this is the standard behavior [1]. So lookup is not the same for `command ` vs `command -v `, and there doesn't seem to be a standard way to lookup the executable started by `command `. `which` seem to fill that gap.
[1] https://pubs.opengroup.org/onlinepubs/007904975/utilities/co...