mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2159 (markdown)
25
SC2159.md
Normal file
25
SC2159.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
## [ 0 ] is true. Use 'false' instead
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
if [ 0 ]
|
||||||
|
then
|
||||||
|
echo "always triggers"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
if false
|
||||||
|
then
|
||||||
|
echo "never triggers"
|
||||||
|
fi
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
`[ str ]` checks whether `str` is non-empty. It doesn't matter if `str` is `0`, it will still be evaluated for non-emptyness.
|
||||||
|
|
||||||
|
Instead, use the command `false` which -- as the manual puts it -- does nothing, unsuccessfully.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
None
|
Reference in New Issue
Block a user