Created SC2272 (markdown)

Vidar Holen
2020-12-30 19:45:34 -08:00
parent 5b44d393f2
commit 43313c5118

26
SC2272.md Normal file

@@ -0,0 +1,26 @@
## Command name contains ==. For comparison, use [ "$var" = value ].
### Problematic code:
```sh
$a/$b==foo/bar
```
### Correct code:
```sh
[ "$a/$b" = "foo/bar" ]
```
### Rationale:
ShellCheck found a command name that contains a `==`. Most likely, this was intended as a kind of comparison.
To compare two values, use `[ value1 = value2 ]`. Both the brackets and the spaces around the `=` are relevant.
### Exceptions:
None, though you can quote the `==` to suppress the warning.
### Related resources:
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!