From d589c771dc75206bb2b6d592435c8316cffd29fb Mon Sep 17 00:00:00 2001 From: Anil Belur Date: Tue, 14 May 2019 23:14:05 +1000 Subject: [PATCH] Handle unbound arrays correctly The change cfe54b794b3814f288009b796e82668ba8846ca1 missed handling unbound arrays with `set -u`. Issue: RELENG-2013 Change-Id: Ic37ce0404f13bff04aa4122c9b1c91add78e2145 Signed-off-by: Anil Belur --- .../notes/handle-unbound-arrays-9a31a444687d18ce.yaml | 14 ++++++++++++++ shell/logs-deploy.sh | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 releasenotes/notes/handle-unbound-arrays-9a31a444687d18ce.yaml diff --git a/releasenotes/notes/handle-unbound-arrays-9a31a444687d18ce.yaml b/releasenotes/notes/handle-unbound-arrays-9a31a444687d18ce.yaml new file mode 100644 index 00000000..1be44d82 --- /dev/null +++ b/releasenotes/notes/handle-unbound-arrays-9a31a444687d18ce.yaml @@ -0,0 +1,14 @@ +--- +fixes: + - | + Fix error with handling unbound arrays for search extensions, when using + `set -u`. The correct way of using this. + + .. code-block:: bash + + set -u + arr=() + echo "output: '${arr[@]}'" + bash: arr[@]: unbound variable + echo "output: '${arr[@]:-}'" + foo: '' diff --git a/shell/logs-deploy.sh b/shell/logs-deploy.sh index a00f0a7a..23660d7a 100644 --- a/shell/logs-deploy.sh +++ b/shell/logs-deploy.sh @@ -21,9 +21,10 @@ else # Handle multiple search extensions as separate values to '-p|--pattern' set -f # Disable pathname expansion + search_exts=() IFS=' ' read -r -a search_exts <<< "${ARCHIVE_ARTIFACTS:-}" pattern_opts=() - for search_ext in "${search_exts[@]}"; + for search_ext in "${search_exts[@]:-}"; do pattern_opts+=("-p" "$search_ext") done -- 2.16.6