mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Created SC1087 (markdown)
19
SC1087.md
Normal file
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.
|
Reference in New Issue
Block a user