mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Give an example code selection for a custom array variable, rather than just talking about $@.
12
SC2145.md
12
SC2145.md
@@ -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.
|
||||||
|
Reference in New Issue
Block a user