I am running this piece of code so that I can match the branch name with a pattern and create port based on which:
nano test.sh
#!/usr/bin/env bash
branch="3.2.1"
re='([0-9]+)\.([0-9]+)\.([0-9]+)'
if [[ $branch =~ "master" ]]; then
port=3000
echo $port
elif [[ $branch =~ $re ]]; then
port="300${BASH_REMATCH[0]}"
echo $port
else
echo "no match found!"
fi
and
bash test.sh
I am expecting 3003
but it is returning 3.2.1