0

Here is a variable called "target"

$ echo $_target
x86_64-linux-gnu

This regex test succeeds...

$ if [[ $_target =~ "x86_64" ]]; then echo "match"; fi
match

But it doesn't test to see if the expression is at the beginning of the line. Let me add the anchor tag to the regex:

$ if [[ $_target =~ "^x86_64" ]]; then echo "match"; fi
$

The line above doesn't indicate a match. Weird.

However, if I take off the quotes around the regular expression, all is good

$ if [[ $_target =~ ^x86_64 ]]; then echo "match"; fi
match

Why do the quotes influence the regular expression test? What am I missing in my understanding to be surprised that the second test above fails to match?

selbie
  • 100,020
  • 15
  • 103
  • 173
  • 4
    possibly answered here: http://stackoverflow.com/questions/218156/bash-regex-with-quotes?rq=1 – pce Feb 23 '13 at 21:23

1 Answers1

1

You should not put the right side of the =~ operator in quotes, as this will mean a string, and not a regex. (source

Lodewijk Bogaards
  • 19,777
  • 3
  • 28
  • 52