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

Specify a minimum requirement for BASH_VERSION #5

Open
navidemad opened this issue Oct 25, 2024 · 0 comments
Open

Specify a minimum requirement for BASH_VERSION #5

navidemad opened this issue Oct 25, 2024 · 0 comments

Comments

@navidemad
Copy link

navidemad commented Oct 25, 2024

The declare command has been available since very early versions of Bash (pre-4.0), so if you have Bash 4.2 or higher, you definitely have access to the declare builtin.

I copied audit.sh and check_indexes.sh into my project and made audit.sh executable:

curl https://raw.githubusercontent.com/speedshop/ids_must_be_indexed/refs/heads/main/audit.sh -o audit.sh
curl https://raw.githubusercontent.com/speedshop/ids_must_be_indexed/refs/heads/main/check_indexes.sh -o check_indexes.sh
chmod +x ./audit.sh
./audit.sh

When I run it, I get:

./check_indexes.sh: line 247: conditional binary operator expected

If I comment out the line causing this error, I get:

Analyzing schema.rb for missing indexes...

Error: This script requires Bash version 4.2 or later for declare -g support.
Your current Bash version is: 3.2.57(1)-release
Please upgrade your Bash version to run this script.

So, it’s likely not a bug but syntax that only works on Bash 4.2+.
If that’s the case, it might be worth updating the README.md or adding a version check in the script itself like:

# Check Bash version 4.2 or high to have support for 'declare'
minimum_required_version="4.2"
if [ -z "$BASH_VERSION" ] || [[ "${BASH_VERSION%%[^0-9.]*}" < "$minimum_required_version" ]]; then
  echo "Error: This script requires Bash version $minimum_required_version or higher."
  exit 1
fi

After i did a basic brew install bash i got the 5.2 and now it works fine

Have a great day

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

1 participant