diff --git a/SC1087.md b/SC1087.md new file mode 100644 index 0000000..4f74522 --- /dev/null +++ b/SC1087.md @@ -0,0 +1,19 @@ +## 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. + +### Contraindications + +If you want the square brackets to be treated literally or as a glob, you can use `${var}[idx]` to prevent this warning. \ No newline at end of file