Skip to content
Vidar Holen edited this page Jan 21, 2015 · 6 revisions

Braces are required when expanding arrays, as in ${array[idx]}.

Problematic code:

echo "$array[@]"

Correct code:

echo "${array[@]}"

Rationale:

For compatibility reasons, $foo[bar] is interpreted as the variable $foo followed by the literal string [bar].

Curly braces are needed to tell the shell that the square brackets are part of the expansion.

Exceptions

If you want the square brackets to be treated literally or as a glob, you can use ${var}[idx] to prevent this warning.

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