From 1811e03485a3a88c0c091ca55678fcf8b78a2b3e Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 25 Feb 2018 18:06:02 -0800 Subject: [PATCH] Created SC2230 (markdown) --- SC2230.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 SC2230.md diff --git a/SC2230.md b/SC2230.md new file mode 100644 index 0000000..dd93d49 --- /dev/null +++ b/SC2230.md @@ -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. \ No newline at end of file