Give an example code selection for a custom array variable, rather than just talking about $@.

Kevin Malachowski
2019-03-27 11:26:29 -07:00
parent 0ca982cb1a
commit c11a85d1d2

@@ -12,6 +12,18 @@ printf "Error: %s\n" "Bad parameters: $@"
printf "Error: %s\n" "Bad parameters: $*" printf "Error: %s\n" "Bad parameters: $*"
``` ```
### Problematic code 2:
```sh
printf "Error: %s\n" "Bad parameters: ${ARRAY_VAR[@]}"
```
### Correct code 2:
```sh
printf "Error: %s\n" "Bad parameters: " "${ARRAY_VAR[@]}"
```
### Rationale: ### Rationale:
The behavior when concatenating a string and array is rarely intended. The preceeding string is prefixed to the first array element, while the succeeding string is appended to the last one. The middle array elements are unaffected. The behavior when concatenating a string and array is rarely intended. The preceeding string is prefixed to the first array element, while the succeeding string is appended to the last one. The middle array elements are unaffected.