What's not machine-friendly about `command -v`'s output? Can you not just use the exit status? Or did you mean that you avoid `which` in favor of `command -v`?
$ which true
/usr/bin/true
$ command -v true
true
$ which ls
/usr/bin/ls
$ command -v ls
alias ls='ls --color=auto'So yes, that's more useful if you're using `which` to determine "Does this name exist as an executable anywhere in the PATH", but most people use it to mean "What will actually be executed if I run this word as a command?"
edit: Or, most often in scripts, it's used just for its exit status to tell whether the command exists to be executed at all.
You are assuming a bit too much here.
Which tells you the preferred executable with that name, while command tells you what will run if you execute it on the current shell.
From what I can tell, one does not replace the other. But yes, for your example of usage, command is more correct.
$ sh -c "which ls; command -v ls"
/bin/ls
/bin/ls
If the script is #!bash rather than #!sh, it’s not even possible to define an alias. $ bash -c "alias ls='ls --color=auto'; which ls; command -v ls"
/bin/ls
/bin/ls