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

A builtin returning the Bash version as a Num #622

Open
lens0021 opened this issue Nov 27, 2024 · 3 comments
Open

A builtin returning the Bash version as a Num #622

lens0021 opened this issue Nov 27, 2024 · 3 comments

Comments

@lens0021
Copy link
Contributor

lens0021 commented Nov 27, 2024

It's out of scope for this PR, but we should probably write a builtin returning the Bash version as a Num.

Originally posted by @hdwalters in #620 (comment)

Along with a builtin to return the Bash version (suggested in a comment on a different PR) we should also add an annotation specifying the minimum Bash version to support a given function or main block.

Originally posted by @hdwalters in #616 (comment)

@hdwalters
Copy link
Contributor

Thanks for creating this issue. I would have got round to it eventually!

@lens0021
Copy link
Contributor Author

lens0021 commented Jan 5, 2025

I think it should expose the fix version as well as the major and the minor.

@hdwalters
Copy link
Contributor

hdwalters commented Jan 5, 2025

I'm running Bash 5.2.21.1; the Amber function I wrote to bypass negative array index validity tests returns 502 for me:

#[allow_absurd_cast]
fun bash_version(): Num {
    let major = trust $ echo "\$\{BASH_VERSINFO[0]}" $ as Num
    let minor = trust $ echo "\$\{BASH_VERSINFO[1]}" $ as Num
    return (major * 100) + minor
}

main {
    if bash_version() >= 402 {
    ...

If we're going to include all four numeric components, extending this to 5022101 or 5002021001 will be unworkable.

Can I suggest that we consider returning an array, and implementing version comparison, at least for [Num] arrays:

let bashver = [5, 2, 21, 1]
if bashver >= [4, 3] {
    // Bash 4.3 or above
}

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

No branches or pull requests

2 participants