Created SC2230 (markdown)

Vidar Holen
2018-02-25 18:06:02 -08:00
parent c7e89264b3
commit 1811e03485

25
SC2230.md Normal file

@@ -0,0 +1,25 @@
## which is non-standard. Use builtin 'command -v' instead.
### Problematic code:
```sh
which grep
```
### Correct code:
```sh
command -v grep
```
### Rationale:
`which` is a non-standard, external tool that locates an executable in PATH. `command -v` is a POSIX standard builtin, which uses the same lookup mechanism that the shell itself would.
### Exceptions:
None
### Related resources:
* [Check if a program exists from a Bash script](https://stackoverflow.com/a/677212/1899640) on StackOverflow.