mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2284 (markdown)
35
SC2284.md
Normal file
35
SC2284.md
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
## Use [ x = y ] to compare values (or quote '==' if literal).
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
if $var == value
|
||||||
|
then
|
||||||
|
echo "Match"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
if [ "$var" = value ]
|
||||||
|
then
|
||||||
|
echo "Match"
|
||||||
|
fi
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found an unquoted `==` after a word.
|
||||||
|
|
||||||
|
This was most likely supposed to be a comparison, so use square brackets as in the correct code.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
If the `==` was supposed to be literal, you can quote it to make ShellCheck ignore it:
|
||||||
|
|
||||||
|
grep '===' file.js
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user