Skip to content

Files

Latest commit

 

History

History
29 lines (17 loc) · 643 Bytes

SC1087.md

File metadata and controls

29 lines (17 loc) · 643 Bytes

Pattern: Missing curly braces for array expansion

Issue: -

Description

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[@]}"

Exceptions

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

Further Reading