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