mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2212 (markdown)
28
SC2212.md
Normal file
28
SC2212.md
Normal file
@@ -0,0 +1,28 @@
|
||||
## Use 'false' instead of empty [/[[ conditionals.
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
if [ ]
|
||||
then
|
||||
echo "Temporarily disabled"
|
||||
fi
|
||||
```
|
||||
|
||||
### Correct code:
|
||||
|
||||
```sh
|
||||
if false
|
||||
then
|
||||
echo "Temporarily disabled"
|
||||
fi
|
||||
```
|
||||
### Rationale:
|
||||
|
||||
`[ ]` is a somewhat obscure way of expressing falsehood, and the behavior is likely intended to allow the incorrectly quoted command `[ $var ]` to still work when the variable is unset.
|
||||
|
||||
POSIX has a more descriptive command `false` for this.
|
||||
|
||||
### Exceptions:
|
||||
|
||||
None. This is a stylistic suggestion, and has no effect on how the script works.
|
Reference in New Issue
Block a user