Skip to content

Commit

Permalink
#1273 Fix array indexing and length handling for sdk ls
Browse files Browse the repository at this point in the history
Cf. https://sdkman.slack.com/archives/CJTNQA94M/p1706573532033689?thread_ts=1706516271.626039&cid=CJTNQA94M

- Array indexing is wrong, it starts at 1 (not 0) and ends at the
  highest index, not at array length -1. You have both in C or Java,
  but shell is different.
- Executed in bash the `${#versions}` is - for whatever reason -
  restricted to four bits. So the maximum value is 15. If the versions
  array is > 15, you have to use `${#versions[@]}` instead (cf.
  https://linuxhandbook.com/array-length-bash/).
  • Loading branch information
ascheman committed Jan 30, 2024
1 parent 6529e01 commit 4a98907
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/bash/sdkman-list.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function __sdkman_offline_list() {
__sdkman_echo_no_colour "--------------------------------------------------------------------------------"

local versions=($(echo ${versions_csv//,/ }))
for ((i = ${#versions} - 1; i >= 0; i--)); do
for ((i = ${#versions[@]}; i > 0; i--)); do
if [[ -n "${versions[${i}]}" ]]; then
if [[ "${versions[${i}]}" == "$CURRENT" ]]; then
__sdkman_echo_no_colour " > ${versions[${i}]}"
Expand Down

0 comments on commit 4a98907

Please sign in to comment.