Skip to content

Files

Latest commit

 

History

History
32 lines (20 loc) · 825 Bytes

SC2179.md

File metadata and controls

32 lines (20 loc) · 825 Bytes

Pattern: Trying to append a string to array with var+=string

Issue: -

Description

It looks like you are trying to append a string to an array with var+=string. This instead appends to the first element of the array (equivalent to var[0]+=three).

Example of incorrect code:

var=(one two)
var+=three

Here the array will contain onethree two.

Instead, append an array to the array with var+=( elements ). This will append the new items to the array.

Example of correct code:

var=(one two)
var+=( three )

Exceptions

If ShellCheck mistakenly thinks the variable is an array when it's not (e.g. because the same name was used in a different context), you can ignore this error.

Further Reading