Created SC2276 (markdown)

Vidar Holen
2020-12-30 20:05:52 -08:00
parent 6a44faff66
commit d777f3877f

37
SC2276.md Normal file

@@ -0,0 +1,37 @@
## This is interpreted as a command name containing '='. Bad assignment or comparison?
### Problematic code:
```sh
"$var"=42
if "$var"=42
then
true
fi
```
### Correct code:
```sh
var=42
if [ "$var" = 42 ]
then
true
fi
```
### Rationale:
ShellCheck found a command name containing an unquoted equals sign `=`. This was likely intended as either a comparison or an assignment.
To compare two values, use e.g. `[ "$var" = "42" ]`
To assign a value, use e.g. `var="42"`
### Exceptions:
None, though you can quote the `=` to make ShellCheck ignore it: `"$var=42"`.
### Related resources:
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!