Skip to content

Conversation

@Chemaclass
Copy link
Member

@Chemaclass Chemaclass commented Jul 27, 2025

📚 Description

Add support for detecting the minimum Bash version and exiting gracefully if unsupported.

Idea from @akinomyoga, thanks!

🔖 Changes

  • Documented the minimum Bash requirement in the README, stating that bashunit requires Bash 3.2 or newer
  • Added a “Requirements” section in the installation guide with the same version information
  • Implemented a runtime version check in the bashunit entrypoint to exit if the Bash version is below 3.2
  • Logged this new feature in the changelog under Unreleased
  • Created a new unit test ensuring bashunit exits with an error for unsupported versions

✅ To-do list

  • I updated the CHANGELOG.md to reflect the new feature or fix
  • I updated the documentation to reflect the changes

🏗️ Follow up idea

Add support for Bash 3.0 and newer

@Chemaclass Chemaclass self-assigned this Jul 27, 2025
@Chemaclass Chemaclass added the enhancement New feature or request label Jul 27, 2025
@Chemaclass Chemaclass enabled auto-merge July 27, 2025 13:01
bashunit Outdated

function _check_bash_version() {
local current_version
current_version="$(bash --version | head -n1 | cut -d' ' -f4 | cut -d. -f1,2)"
Copy link

@akinomyoga akinomyoga Jul 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work. It finds bash in the PATH, which isn't necessarily the current Bash version. In particular, when I would like to test a Bash script with different Bash versions, I would do

$ bash-3.0 ./bashunit ...
$ bash-3.1 ./bashunit ...
$ ...
$ bash-5.3 ./bashunit ...

However, this _check_bash_version always sees bash in PATH, which doesn't work.

Instead, the shell variable BASH_VERSION should be used. If you can assume bash >= 2.0, you may also use BASH_VERSINFO array. Actually, you can simply check BASH_VERSINFO because if it doesn't exist, it's anyway out of support.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I normally use zsh, so the change I think would be the best compromise (to support different terminal), is:

  1. check first for the native Bash version with $BASH_VERSINFO in case such variable exists
  2. Otherwise, as fallback then use the bash -v

@Chemaclass Chemaclass disabled auto-merge July 27, 2025 13:23
@Chemaclass Chemaclass requested a review from akinomyoga July 27, 2025 15:47
@Chemaclass Chemaclass merged commit 343e357 into main Jul 27, 2025
18 checks passed
@Chemaclass Chemaclass deleted the feat/check-min-supported-bash-version-check branch July 27, 2025 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants