From 552971e1caec235ac5e436c926c2118ed83f33cc Mon Sep 17 00:00:00 2001 From: stuff-and-nonsense Date: Sat, 11 May 2019 16:52:34 +0200 Subject: [PATCH] command -v exit code with multiple parameters --- SC2230.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) 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