Various Shell Script Fixes and Improvements - Part One

see #4023

Closes #4051.

PiperOrigin-RevId: 177279457
diff --git a/scripts/bash_completion_test.sh b/scripts/bash_completion_test.sh
index 3bf7999..adb75f7 100755
--- a/scripts/bash_completion_test.sh
+++ b/scripts/bash_completion_test.sh
@@ -68,7 +68,7 @@
         #
         # Alias expansion still inserts an extra space after 'blaze',
         # though, hence the following sed.  Not sure why.
-        for i in ${COMMAND_ALIASES[@]}; do
+        for i in "${COMMAND_ALIASES[@]}"; do
           echo "alias $i=\"echo $i'\""
         done
         echo -en "$input'"
@@ -82,7 +82,7 @@
 # e.g. assert_expansion 'foo' 'foo_expand' 'flag1=bar;flag2=baz'
 assert_expansion() {
     local prefix=$1 expected=$2 flags=${3:-}
-    for i in ${COMMAND_ALIASES[@]}; do
+    for i in "${COMMAND_ALIASES[@]}"; do
       local nprefix="$i $prefix"
       local nexpected="$i $expected"
       assert_equals "$nexpected" "$(expand "$nprefix\t" "$flags" "/dev/null")"
@@ -100,7 +100,7 @@
 assert_expansion_error_not_contains() {
   local prefix=$1 not_expected=$2 flags=${3:-}
   local temp_file="$(mktemp "${TEST_TMPDIR}/tmp.stderr.XXXXXX")"
-  for i in ${COMMAND_ALIASES[@]}; do
+  for i in "${COMMAND_ALIASES[@]}"; do
     local nprefix="$i "
     expand "$nprefix\t" "$flags" "$temp_file" > /dev/null
     assert_not_contains "$not_expected" "$temp_file"
diff --git a/scripts/bootstrap/compile.sh b/scripts/bootstrap/compile.sh
index a12b2e3..cd05bad 100755
--- a/scripts/bootstrap/compile.sh
+++ b/scripts/bootstrap/compile.sh
@@ -20,7 +20,7 @@
 LIBRARY_JARS=$(find third_party -name '*.jar' | grep -Fv /javac-9-dev-r3297-4.jar | grep -Fv /javac-9-dev-4023-3.jar | grep -Fv /javac7.jar | grep -Fv JavaBuilder | grep -Fv third_party/guava | grep -Fv third_party/guava | grep -ve third_party/grpc/grpc.*jar | tr "\n" " ")
 GRPC_JAVA_VERSION=1.7.0
 GRPC_LIBRARY_JARS=$(find third_party/grpc -name '*.jar' | grep -e .*${GRPC_JAVA_VERSION}.*jar | tr "\n" " ")
-GUAVA_VERSIONE=23.1
+GUAVA_VERSION=23.1
 GUAVA_JARS=$(find third_party/guava -name '*.jar' | grep -e .*${GUAVA_VERSION}.*jar | tr "\n" " ")
 LIBRARY_JARS="${LIBRARY_JARS} ${GRPC_LIBRARY_JARS} ${GUAVA_JARS}"
 
@@ -41,7 +41,7 @@
   TEMP_FOR_SWAP="${LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]}"
   LIBRARY_JARS_ARRAY[$ERROR_PRONE_INDEX]="${LIBRARY_JARS_ARRAY[$GUAVA_INDEX]}"
   LIBRARY_JARS_ARRAY[$GUAVA_INDEX]="$TEMP_FOR_SWAP"
-  LIBRARY_JARS="${LIBRARY_JARS_ARRAY[@]}"
+  LIBRARY_JARS="${LIBRARY_JARS_ARRAY[*]}"
 fi
 
 DIRS=$(echo src/{java_tools/singlejar/java/com/google/devtools/build/zip,main/java,tools/xcode-common/java/com/google/devtools/build/xcode/{common,util}} third_party/java/dd_plist/java ${OUTPUT_DIR}/src)
diff --git a/scripts/release/release.sh b/scripts/release/release.sh
index 6a2559a..3b18fd8 100755
--- a/scripts/release/release.sh
+++ b/scripts/release/release.sh
@@ -122,11 +122,11 @@
 function apply_cherry_picks() {
   echo "Applying cherry-picks"
   # Apply cherry-picks
-  for i in $@; do
+  for commit in "$@"; do
     local previous_head="$(git rev-parse HEAD)"
-    echo "  Cherry-picking $i"
-    git cherry-pick $i >/dev/null || {
-      echo "Failed to cherry-pick $i. please resolve the conflict and exit." >&2
+    echo "  Cherry-picking ${commit}"
+    git cherry-pick ${commit} >/dev/null || {
+      echo "Failed to cherry-pick ${commit}. please resolve the conflict and exit." >&2
       echo "  Use 'git cherry-pick --abort; exit' to abort the cherry-picks." >&2
       echo "  Use 'git cherry-pick --continue; exit' to resolve the conflict." >&2
       bash
@@ -137,7 +137,7 @@
     }
     # Add the origin of the cherry-pick in case the patch-id diverge and we cannot
     # find the original commit.
-    git notes --ref=cherrypick add -f -m "$i"
+    git notes --ref=cherrypick add -f -m "${commit}"
   done
   return 0
 }
@@ -147,9 +147,9 @@
   local branch="${1:-HEAD}"
   local baseline="${2:-$(get_release_baseline "${branch}")}"
   local changes="$(git log --pretty=format:%H "${baseline}~".."${branch}")"
-  for i in ${changes}; do
-    if git notes --ref=release show $i &>/dev/null; then
-      echo $i
+  for change in ${changes}; do
+    if git notes --ref=release show ${change} &>/dev/null; then
+      echo ${change}
       return 0
     fi
   done
diff --git a/scripts/release/relnotes.sh b/scripts/release/relnotes.sh
index 94edb04..d88ef46 100755
--- a/scripts/release/relnotes.sh
+++ b/scripts/release/relnotes.sh
@@ -100,8 +100,8 @@
   for i in "${RELNOTES_TYPES[@]}"; do
     eval "RELNOTES_${i}=()"
   done
-  for i in $@; do
-    extract_release_note $i
+  for commit in $@; do
+    extract_release_note "${commit}"
   done
 }