Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Problems with array indexing and length handling in sdkman-list.sh #1273

Open
ascheman opened this issue Jan 30, 2024 · 0 comments · May be fixed by #1274
Open

Bug: Problems with array indexing and length handling in sdkman-list.sh #1273

ascheman opened this issue Jan 30, 2024 · 0 comments · May be fixed by #1274

Comments

@ascheman
Copy link

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/).
ascheman added a commit to ascheman/sdkman-cli that referenced this issue Jan 30, 2024
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/).
@ascheman ascheman linked a pull request Jan 30, 2024 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant