|
|
Log in / Subscribe / Register

Debian's which hunt

Debian's which hunt

Posted Oct 28, 2021 18:08 UTC (Thu) by Taywee (guest, #154131)
In reply to: Debian's which hunt by abatters
Parent article: Debian's which hunt

Sure, but for scripting purposes, the primary use of it that I've seen is to answer the question "can I run this command?"
If you need to find whether an executable exists somewhere in PATH even if a built-in, function, or alias would subvert it, then the GNU which behavior is going to be more useful, but I can't think of a lot of use-cases for that, honestly.


to post comments

Debian's which hunt

Posted Oct 28, 2021 18:44 UTC (Thu) by joey (guest, #328) [Link]

One use case is eg:

#!/bin/sh
foo=$(which foo)
PATH=something:else
$foo

Whether that will work with command -v will depend on what shell /bin/sh uses, since different shells read different dotfiles which could contain aliases. Yeah, I had a case of this in my ~/bin/.

Debian's which hunt

Posted Oct 28, 2021 20:37 UTC (Thu) by jond (subscriber, #37669) [Link]

Here’s another example in a high profile tool that by coincidence I was working on recently

https://github.com/apache/maven/pull/556

Debian's which hunt

Posted Oct 29, 2021 10:27 UTC (Fri) by GhePeU (subscriber, #56133) [Link]

$ alias "fakeprogram"="/usr/bin/notarealprogram -a"

$ which fakeprogram; echo $?
1

$ command -v fakeprogram; echo $?
alias fakeprogram='/usr/bin/notarealprogram -a'
0

$ command -V fakeprogram; echo $?
fakeprogram is aliased to `/usr/bin/notarealprogram -a'
0


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds