diff --git a/SC2128.md b/SC2128.md index e68e258..ea753ac 100644 --- a/SC2128.md +++ b/SC2128.md @@ -1,4 +1,4 @@ -## Expanding an array without an index only gives the first element. +## Expanding an array without an index only gives the element in the index 0. ### Problematic code: @@ -22,7 +22,7 @@ done ### Rationale: -When referencing arrays, `$myarray` is equivalent to `${myarray[0]}` -- it results in only the first of multiple elements. +When referencing arrays, `$myarray` is equivalent to `${myarray[0]}` -- which is usually the first of multiple elements. This is also true for associative arrays. Therefore, if 0 (zero) is not a valid key, `$myarray` expands to an empty string. To get all elements as separate parameters, use the index `@` (and make sure to double quote). In the example, `echo "${myarray[@]}"` is equivalent to `echo "foo" "bar"`.