From 2c8bca9ffa1e6496339bbcd0b27236249509bb14 Mon Sep 17 00:00:00 2001 From: James Guthrie Date: Tue, 21 Apr 2015 09:42:14 +0200 Subject: [PATCH] Created SC2091 (markdown) --- SC2091.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 SC2091.md diff --git a/SC2091.md b/SC2091.md new file mode 100644 index 0000000..899c9e7 --- /dev/null +++ b/SC2091.md @@ -0,0 +1,17 @@ +## Remove surrounding $() to avoid executing output. + +### Problematic code: + + if $(which "false"); then echo "true"; fi + +### Correct code: + + if which "false" >/dev/null >2&1; then echo "true"; fi + +### Rationale: + +If the `$()` subshell produces an output it will be evaluated by the `if` statement, this could result in the execution of the output, which will result in different behaviour than intended. + +### Exceptions: + +None. \ No newline at end of file