An Open Source project I contribute to has a dependency on which
that I'd like to remove, as some Linux distros (like the cloud version of Fedora 20) don't ship with it by default, and I believe it's ugly to force its install, given how trivial our use of it is.
All we're doing is finding the path to the Java binary, then using that info to set $JAVA_HOME
.
Is there a way to do that with Bash built-ins? In general, how can I somewhat-elegantly find a binary while minimizing dependencies (like which
)? Or is it a better call to just use which
, for example if the only alternative is to run find
against directories in $PATH
and the community believes that to be exceedingly inelegant?
Note that it's extremely ineffective to Google for which
-related things.
which
, aswhich
is an external program using (slightly) different logic than the shell does itself, and thus can potentially give you a potentially inaccurate result!type
uses the shell's built-in resolution, and is guaranteed to behave the same way the shell really will in practice.