diff --git a/SC2230.md b/SC2230.md index dd93d49..8308064 100644 --- a/SC2230.md +++ b/SC2230.md @@ -20,6 +20,28 @@ command -v grep None +### Caveats: + +On macOS 10.13.6, command -v appears to take multiple parameters: + +``` +# grep is in /usr/bin/grep +# foobar is not in path +# +$ command -v -- grep foobar; echo $? +0 +``` + +but succeeds (with exit code 0) if *any* command exists. In the above +example, it should have failed and exited with 1 unless *all* commands +exist. + +An alternative is: + +$ hash + +Which observes the standard behaviour of failures. + ### Related resources: * [Check if a program exists from a Bash script](https://stackoverflow.com/a/677212/1899640) on StackOverflow. \ No newline at end of file