From: Anil Belur Date: Tue, 14 May 2019 13:14:05 +0000 (+1000) Subject: Handle unbound arrays correctly X-Git-Tag: v0.38.0~8^2 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=7c671f9710451d603dfefe95dd332d594e9e4896;p=releng%2Fglobal-jjb.git 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 --- 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