Link to home
Start Free TrialLog in
Avatar of s1m0ne
s1m0neFlag for United States of America

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jlevie
jlevie

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
Avatar of s1m0ne

ASKER

amit_g,

That's the stuff. Thanks a lot!

s1m0ne