mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 11:19:45 +08:00
command -v exit code with multiple parameters
22
SC2230.md
22
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 <file1> <file2>
|
||||
|
||||
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.
|
Reference in New Issue
Block a user