Pattern: Missing curly braces for array expansion
Issue: -
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.
Example of incorrect code:
echo "$array[@]"
Example of correct code:
echo "${array[@]}"
If you want the square brackets to be treated literally or as a glob, you can use ${var}[idx]
to prevent this warning.