Skip to content
Vidar Holen edited this page Sep 8, 2020 · 1 revision

In POSIX sh, += is undefined.

(or "In dash, ... is not supported." when using dash)

Problematic code:

var="Hello "
var+="World"

Correct code:

var="Hello "
var="${var}World"

Rationale:

Using += to concatenate to an existing variable is a ksh/bash extension. For POSIX sh or dash, write out the full expression. Be careful to use braces if the text you append could be confused for a variable (as in the example, to avoid $varWorld being interpreted as ${varWorld})

Exceptions:

None.

Related resources:

  • Help by adding links to BashFAQ, StackOverflow, man pages, POSIX, etc!

ShellCheck

Each individual ShellCheck warning has its own wiki page like SC1000. Use GitHub Wiki's "Pages" feature above to find a specific one, or see Checks.

Clone this wiki locally
You can’t perform that action at this time.