i am creating a script that will help updating the GoLang compile binary in a GNU/Linux system.
but it fail
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# set -e
# ==============================================================================
# title : Semi Automatic Update GoLang
# description : Script for Install, setup path, permission and update golang
# author : Walddys Emmanuel Dorrejo Céspedes
# usage : bash up_install.sh
# notes : Execute this Script will ask sudo password
# dependencies : wget awk sed curl tar
# ==============================================================================
## Get Golang Versions from repository
declare -a go_jversion go_sversion
readarray -t go_jversion < <(curl -s https://go.googlesource.com/go/+refs?format=JSON | grep -Eo "go[0-9]\.[^\"]+" | sort -V)
## Delete go_versions RC and Beta from the pool.
for i in "${!go_jversion[@]}"; do
if [[ "${go_jversion[i]}" =~ (rc|beta) ]]; then
unset "go_jversion[i]"
fi
done
unset go_sversion # Not allow to grow indefinitely the pool when re-execute the scripts
for i in "${!go_jversion[@]}"; do
set -vx
## Create an array of the stables versions (Those versions that repeat more than or equal to 2 are stables)
# if [[ "${go_jversion[i]}" == "${go_jversion[i + 1]}" ]] && [[ "${go_sversion[i - 1]}" != "${go_jversion[i + 1]}" ]]; then
# go_sversion+=("${go_jversion[i]}")
# fi
In this section i am comparing major version + minimum version, to exclude the patch version of the array, but the condition after the "&&", the array "${go_sversion[$i -1]}"
is expanding null in each cycle of the loop, when i am assigning a value in a cycle before.
## Create an array of the stables versions (Those versions that repeat more than or equal to 2 are stables) (second version)
if [[ "${go_jversion[$i]}" == "${go_jversion[$i + 1]}" && "${go_sversion[$i - 1]}" != "${go_jversion[$i]}" ]]; then
go_sversion+=("${go_jversion[$i]}")
echo "${!go_sversion[$i]}"
fi
set +vx
done
echo "${go_sversion[@]}"
echo "${!go_sversion[@]}"
My issue is in the section where "${go_sversion[$i -1]}"
, why is not expanding?
assign value to "${go_sversion[$i -1]}"
the value display in the next cycle of the loop