4 ms·
trivia: `which` is not the same which on all distros - on Ubuntu for example it's a super simple shell script named `which` which supports one single param (-a)
by stonesweep 6y ago
trivia: `which` is not the same which on all distros - on Ubuntu for example it's a super simple shell script named `which` which supports one single param (-a), not the compiled binary that you have on say Arch - and the features are different between them - I can't for example run `which --skip-tilde which` on Ubuntu, invalid usage.
Many scripters who need wide compatibility of "which" fall back to the builtins `type` and `command` as they resolve any bash aliases set and give you a more truthful (sic) output than relying on `which` and bash is bash on all platforms:
# command -v which
/usr/bin/which
# type which
which is hashed (/usr/bin/which)
$0.02 for your next adventure down the `which` rabbit hole. :)
- akira2501 6y agoIt can also be a shell builtin: akira@akira:~ which which which: shell built-in command
- stonesweep 6y agoVery true, I missed that thanks - to illustrate how that could be important (to the scripter): kaneda@tetsuo:~ which type kaneda@tetsuo:~ type type type is a shell builtin kaneda@tetsuo:~ command -v type type This was on Ubuntu, the which script doesn't resolve type or command silently, while on say Arch it's verbose ("can't find type in (paths ... ...)" so even a failure-to-find emits differently for the `which` crowd.
- turminal 6y ago> Many scripters who need wide compatibility of "which" fall back to the builtins `type` and `command` as they resolve any bash aliases set When wide compatibility is needed it is best to avoid bash specific solutions.
- account42 6y ago`command -v` is standard POSIX sh [0] [0] https://pubs.opengroup.org/onlinepubs/9699919799/utilities/command.html https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c...