mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC2285 (markdown)
27
SC2285.md
Normal file
27
SC2285.md
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
## Remove spaces around += to assign (or quote '+=' if literal).
|
||||||
|
|
||||||
|
### Problematic code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
var += "my text"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Correct code:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
var+="my text"
|
||||||
|
```
|
||||||
|
|
||||||
|
### Rationale:
|
||||||
|
|
||||||
|
ShellCheck found an unquoted `+=` after a word. To append text to a variable, remove spaces around `+=` as in the example.
|
||||||
|
|
||||||
|
### Exceptions:
|
||||||
|
|
||||||
|
If the `+=` was supposed to be literal, you can quote it to make ShellCheck ignore it:
|
||||||
|
|
||||||
|
grep '+=' files..
|
||||||
|
|
||||||
|
### Related resources:
|
||||||
|
|
||||||
|
* Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!
|
Reference in New Issue
Block a user