Created SC1087 (markdown)

koalaman
2014-11-22 08:56:30 -08:00
parent e3fc756269
commit f3326a503b

19
SC1087.md Normal file

@@ -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.