Equivalent Of Regex Matching Operator Before Bash Version 3

Hello,

The following is an example from http://www.tldp.org/LDP/abs/html/bashver3.html for bash version 3:

----------
#!/bin/bash

variable="This is a fine mess."

echo "$variable"

if [[ "$variable" =~ "T*fin*es*" ]]
# Regex matching with =~ operator within [[ double brackets ]].
then
  echo "match found"
      # match found
fi
----------

How can one do the same thing in earlier versions of bash (2 for instance)?

Thanks in advance,

s1m0ne

LVL 1
s1m0neAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amit_gCommented:
if [[ $(echo "$variable" | egrep -c "T*fin*es*") -gt 0 ]]
then
  echo "match found"
else
  echo "match not found"
fi

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jlevieCommented:
I don't think that's possible with Bash2, but you can always do something like:

...
echo $variable | grep -e "T*fin*es*" >/dev/null
if [ $? -eq 0 ]; then
  echo "match found"
fi
s1m0neAuthor Commented:
amit_g,

That's the stuff. Thanks a lot!

s1m0ne
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.