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