Once upon a time I would have been more particular about the “which issue”. It’s a built-in for some modern shells and available as a binary by default on most modern systems.
You are correct though, if you want to write a 100% POSIX compliant shell script you’re better off using command, type or actually looping over the contents of $PATH and checking for the presence of your desires binary.
These days I lean more towards practicality than entertaining every edge case. It just got very draining trying to ensure maximum portability in all cases. Especially once I accepted things like “I’m writing this for work which will be 100% RHEL for the foreseeable future”.
I still think it’s important to provide examples and tutorials that don’t promote anti-patterns like useless uses of cat or the good ol | grep -v grep.
Alternatively, use your shell however you want. And
which
isn’t POSIX so I wouldn’t use that in a shell script you intend to share.Once upon a time I would have been more particular about the “which issue”. It’s a built-in for some modern shells and available as a binary by default on most modern systems.
You are correct though, if you want to write a 100% POSIX compliant shell script you’re better off using
command
,type
or actually looping over the contents of$PATH
and checking for the presence of your desires binary.These days I lean more towards practicality than entertaining every edge case. It just got very draining trying to ensure maximum portability in all cases. Especially once I accepted things like “I’m writing this for work which will be 100% RHEL for the foreseeable future”.
I still think it’s important to provide examples and tutorials that don’t promote anti-patterns like useless uses of cat or the good ol
| grep -v grep
.