0

I have the following bash script:

#!/bin/bash
FILE_CONTENT="fix: 110256 Módulo > Recurso"
REGEX1="^none:\s.*"
REGEX2="^(feat|Feat|feature|Feature|fix|Fix|break|Break|docs|Docs):\s[0-9]{1,}\s.*"
if [[ $FILE_CONTENT =~ $REGEX1 ]]; then
 echo "Commit não incluído no CHANGELOG!"
fi

if [[ $FILE_CONTENT =~ $REGEX2 ]]; then
 echo "Commit incluído no CHANGELOG!"
else
  echo "Bad commit \"$FILE_CONTENT\", verifique o padrão."
 echo $ERROR_MSG
 exit 1
fi

The script above works fine on a linux box, but not works on a Macos.

When running in a Macos, I'm getting the "Bad commit \"$FILE_CONTENT\", verifique o padrão." message.

For some reason the REGEX is not working as expected in the Macos.

How can I have a bash script that works in both linux and macos ?

Kleyson Rios
  • 2,597
  • 5
  • 40
  • 65
  • 2
    Replace `\s` with `[[:blank:]]` – anubhava Jul 13 '22 at 14:32
  • 3
    Please read [correct-bash-and-shell-script-variable-capitalization](https://stackoverflow.com/questions/673055/correct-bash-and-shell-script-variable-capitalization) and copy/paste your script into http://shellcheck.net and fix any bugs it finds as the `bash` tag you used instructs you to do before posting a question. – Ed Morton Jul 13 '22 at 14:36
  • `\s` is nonstandard; some regex engines support it, some don't. Use `[[:space:]]` instead. – Gordon Davisson Jul 13 '22 at 20:52

0 Answers0