user1990571
user1990571

Reputation: 9

Pattern matching in ksh script

I have a URL parameters in a variable like

a=44&search=My World

here I want to do a pattern matching like

if [ $a =~ "search" ] ;
then
   value=1
else
   value=0

fi

But it is not working in KSH script.

Upvotes: 0

Views: 7767

Answers (2)

bruzer
bruzer

Reputation: 1

found=`echo $a | grep search`
if [ -z $found ]; then
  value=0
else
  value=1
fi

Upvotes: 0

cdarke
cdarke

Reputation: 44374

You need [[ for ksh regular expressions, not the Bourne shell [. Although in this case it hardly seems worth using an RE.

So:

if [[ $a =~ "search" ]]
then 
    value=1 
else 
    value=0
fi

Upvotes: 1

Related Questions