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

mapfile: command not found in zsh #626

Closed
LeonKalt opened this issue Feb 19, 2024 · 4 comments
Closed

mapfile: command not found in zsh #626

LeonKalt opened this issue Feb 19, 2024 · 4 comments
Labels

Comments

@LeonKalt
Copy link

Describe the bug

When running the hooks locally in a zsh mapfile is not available this breaks all hooks loading the new _common.sh

How can we reproduce it?

    - repo: https://github.com/antonbabenko/pre-commit-terraform
      rev: v1.87.0
      hooks:
        - id: terraform_fmt

run in zsh

Environment information

  • OS: MacOS Apple Silicon
  • uname -a and/or systeminfo | Select-String "^OS" output:
Darwin MAC 23.3.0 Darwin Kernel Version 23.3.0: Wed Dec 20 21:30:44 PST 2023; root:xnu-10002.81.5~7/RELEASE_ARM64_T6000 arm64
  • Tools availability and versions:
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin23)
pre-commit 3.6.0
Terraform v1.7.1
Python 3.11.7
Python 3.11.7
checkov 3.2.0
infracost SKIPPED
terraform-docs SKIPPED
terragrunt version 0.55.1
terrascan SKIPPED
TFLint version 0.50.3
+ ruleset.terraform (0.5.0-bundled)
tfsec SKIPPED
trivy Version: 0.49.1
Vulnerability DB:
  Version: 2
  UpdatedAt: 2022-06-24 06:06:57.585311457 +0000 UTC
  NextUpdate: 2022-06-24 12:06:57.585311157 +0000 UTC
  DownloadedAt: 2022-06-24 08:02:01.406102 +0000 UTC
tfupdate SKIPPED
hcledit SKIPPED
flock SKIPPED
  • .pre-commit-config.yaml:
file content
    - repo: https://github.com/antonbabenko/pre-commit-terraform
      rev: v1.87.0
      hooks:
        - id: terraform_fmt
@LeonKalt LeonKalt added area/local_installation bug Something isn't working labels Feb 19, 2024
@robinbowes
Copy link
Contributor

mapfile was introduced in bash 4.0.

MacOS uses zsh by default, and only installs v3.x of bash by default.

We can replace mapfile with something like this:

dir_paths_unique=()
while IFS= read -r line ; do
  dir_paths_unique+=("$line)
done < <(echo "${dir_paths[@]}" | tr ' ' '\n' | sort -u)

@yermulnik
Copy link
Collaborator

yermulnik commented Feb 19, 2024

Thanks for catching this. Supporting older and newer Bash is cumbersome =(
Please check whether #627 fixes the issue.

@LeonKalt
Copy link
Author

Thx for the quick fix. The new update resolved the issue

@MaxymVlasov
Copy link
Collaborator

Fixed in v1.87.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants