Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • 4
    I 100% agree with using command -v, I use it all the time, to check for command availability. For example, command -v CMD > /dev/null || echo 'CMD not found' No stupid ifs required!! Commented Aug 13, 2012 at 18:37
  • 3
    @TechZilla: why are 'if' statements stupid? Commented Mar 9, 2015 at 16:36
  • 4
    POSIX shell is not required to implement command -v option. See stackoverflow.com/q/34572700/1175080. Commented Jan 3, 2016 at 2:53
  • 2
    command -v does not do exactly what which does: The latter exits with non-zero code, if the argument is an alias or a shell function. Commented Apr 28, 2021 at 21:21
  • 1
    In zsh, command -v will happily print out an alias. See my answer for a solution which works in both zsh and bash. Commented Jan 13, 2022 at 7:13