Look at this if block:
#!/bin/bash
str="m.m"
if [[ "${str}" =~ "m\.m" ]]; then
echo "matched"
else
echo "not matched"
exit 1
fi
exit 0
This should print "matched", but it doesn't. Where am I going wrong?
bashregular expression
Look at this if block:
#!/bin/bash
str="m.m"
if [[ "${str}" =~ "m\.m" ]]; then
echo "matched"
else
echo "not matched"
exit 1
fi
exit 0
This should print "matched", but it doesn't. Where am I going wrong?
Best Answer
You need to remove the quoting in the regex match.
From the bash man page:
So with the quotes, you're using good-old string matching.
If you need spaces in the pattern, just escape them: