From c11a85d1d22030fbf846eee09a2dce1f896fa5ae Mon Sep 17 00:00:00 2001 From: Kevin Malachowski Date: Wed, 27 Mar 2019 11:26:29 -0700 Subject: [PATCH] Give an example code selection for a custom array variable, rather than just talking about $@. --- SC2145.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/SC2145.md b/SC2145.md index 311caab..05550a4 100644 --- a/SC2145.md +++ b/SC2145.md @@ -12,6 +12,18 @@ 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: 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.