unixboy

which no longer cool?

TIL – which is actually really rubbish and we should all be using command -v instead. It turns out that command -v knows about aliases because it is an internal shell command – and not an external binary (as which is). Cursor definitely prefers command -v over which when you ask it to assist with bash scripts.

$ which ls
/usr/bin/ls

$ command -v ls
alias ls='ls --color=auto'

In scripting, both which and command -v return -1 if the binary does not exist –

$ command -v notacommand
$ echo $?
1

$ which notacommand
$ echo $?
1

Naturally there is a Hacker News thread on this.

100 Bytes Theme by Marc Armengou