From 1a633f3a551154ac3c70bfdc5263d73d8b3d9f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sun, 31 May 2020 10:56:33 +0300 Subject: [PATCH] java, make: avoid errors in nounset mode on Ubuntu 14 and 16 --- completions/java | 24 ++++++++++++++---------- completions/make | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/completions/java b/completions/java index e1c98271969..d0f70ae6a6c 100644 --- a/completions/java +++ b/completions/java @@ -88,10 +88,12 @@ _java_classes() fi done - # remove class extension - COMPREPLY=(${COMPREPLY[@]%.class}) - # convert path syntax to package syntax - COMPREPLY=(${COMPREPLY[@]//\//.}) + if ((${#COMPREPLY[@]} != 0)); then + # remove class extension + COMPREPLY=(${COMPREPLY[@]%.class}) + # convert path syntax to package syntax + COMPREPLY=(${COMPREPLY[@]//\//.}) + fi } # available packages completion @@ -111,12 +113,14 @@ _java_packages() command sed -e 's|^'$i'/||')) fi done - # keep only packages - COMPREPLY=($(tr " " "\n" <<<"${COMPREPLY[@]}" | command grep "/$")) - # remove packages extension - COMPREPLY=(${COMPREPLY[@]%/}) - # convert path syntax to package syntax - cur="${COMPREPLY[*]//\//.}" + if ((${#COMPREPLY[@]} != 0)); then + # keep only packages + COMPREPLY=($(tr " " "\n" <<<"${COMPREPLY[@]}" | command grep "/$")) + # remove packages extension + COMPREPLY=(${COMPREPLY[@]%/}) + # convert path syntax to package syntax + cur="${COMPREPLY[*]//\//.}" + fi } # java completion diff --git a/completions/make b/completions/make index e84c780e551..96517c217a4 100644 --- a/completions/make +++ b/completions/make @@ -154,7 +154,7 @@ _make() local IFS=$' \t\n' script=$(_make_target_extract_script $mode "$cur") COMPREPLY=($(LC_ALL=C \ $1 -npq __BASH_MAKE_COMPLETION__=1 \ - "${makef[@]}" "${makef_dir[@]}" .DEFAULT 2>/dev/null | + ${makef+"${makef[@]}"} "${makef_dir[@]}" .DEFAULT 2>/dev/null | command sed -ne "$script")) if [[ $mode != -d ]]; then