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.
The POSIX-ly correct way:
cmd=$(command -v whatever)
Maybe by parsing the output of the shell builtin type ?
~/ type python
python is /usr/bin/python
~/ type type
type is a shell builtin
Tested with zsh, bash and sh
If you are using bash, the option -P gives you directly the result you want:
~/ type -P python
/usr/bin/python
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With