I have a shell script for updating a project's version automatically on commit that's working perfectly on zsh (on macOS Catalina) and not working on bash (on Ubuntu 20.04).
When running the script, I get the following error:
Syntax error: "(" unexpected (expecting "then")
On the following line:
if [[ $commit_title =~ (into )([A-Za-z0-9-]+) ]]
then
merge_branch=${BASH_REMATCH[2]}
else
merge_branch=$main_branch
fi
And if I remove the block of code that is using bash rematch I get the following error:
1: eval: Syntax error: "(" unexpected
I use eval in multiple places, for example:
if eval '[[ $current_branch =~ '"^($git_flow_from)$"' ]]' && eval '[[ $merge_branch =~ '"^($git_flow_to)$"' ]]'
then
echo 'Skipping version update for this merge...'
exit 0
fi
You can see the whole script here for context (I did not include it in the question because it is a bit long): https://github.com/celiavelmar/conventional-pre-commits/blob/master/scripts/update_version.sh
What am I doing wrong? Thanks in advance!