Created SC2091 (markdown)

James Guthrie
2015-04-21 09:42:14 +02:00
parent 9eee7f1610
commit 2c8bca9ffa

17
SC2091.md Normal file

@@ -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.