0

When I call bin/console --version in a Symfony project from my terminal, I get Symfony 4.4.3 (env: dev, debug: true) I like to do a match to see that verifies that the result of the command does in fact match the expected pattern.

I've got this pattern: https://regex101.com/r/n2hBR8/1

I've tried several things in my Bash script, but I can't get it to work:

#symfonyVersionRegex="Symfony\s\d{1}.*"
#symfonyVersionRegex="^Symfony\s\d{1}.*$"
symfonyVersionRegex="^Symfony\s\d.*$"

symfonyVersionRaw=`bin/console --version`

if [[ symfonyVersionRaw =~ $symfonyVersionRegex ]]; then
    echo Version number found
else
    echo Version number NOT found
fi

When I echo the symfonyVersionRaw I get the expected version string, so that works but no matter what I try, I always get a negative result ("Version number NOT found").

1 Answers1

0

First, I think you have an error where you do not put $ in front of symfonyVersionRaw.

Then you should match digits with [0-9] or with [[:digit:]].

Take a look here: How to match digits in regex.

nobody
  • 1,545
  • 12
  • 19