Docs feedback: ssh-keys advice for "which" command
https://docs.gitlab.com/ee/ci/ssh_keys/#ssh-keys-when-using-the-docker-executor
The example here recommends using which
command to check if a program is available or not.
This isn't a good way to do it, it would be better to use command -v
here
as in this post: https://stackoverflow.com/questions/592620/how-can-i-check-if-a-program-exists-from-a-bash-script
Avoid which. Not only is it an external process you're launching for doing very little (meaning builtins like hash, type or command are way cheaper), you can also rely on the builtins to actually do what you want, while the effects of external commands can easily vary from system to system.
- Many operating systems have a which that doesn't even set an exit status, meaning the if which foo won't even work there and will always report that foo exists, even if it doesn't (note that some POSIX shells appear to do this for hash too).
- Many operating systems make which do custom and evil stuff like change the output or even hook into the package manager.