mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2091 (markdown)
17
SC2091.md
Normal file
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.
|
Reference in New Issue
Block a user