-
-
Notifications
You must be signed in to change notification settings - Fork 41
Add minimum supported Bash version check #460
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
Conversation
bashunit
Outdated
|
|
||
| function _check_bash_version() { | ||
| local current_version | ||
| current_version="$(bash --version | head -n1 | cut -d' ' -f4 | cut -d. -f1,2)" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- check first for the native Bash version with
$BASH_VERSINFOin case such variable exists - Otherwise, as fallback then use the
bash -v
📚 Description
Add support for detecting the minimum Bash version and exiting gracefully if unsupported.
🔖 Changes
✅ To-do list
CHANGELOG.mdto reflect the new feature or fix🏗️ Follow up idea
Add support for Bash 3.0 and newer