2 SC2285
Joachim Ansorg edited this page 2021-11-12 20:00:36 +01:00

Remove spaces around += to assign (or quote '+=' if literal).

Problematic code:

var += "my text"

Correct code:

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..
  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!