Reputation: 9
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
Reputation: 1
found=`echo $a | grep search`
if [ -z $found ]; then
value=0
else
value=1
fi
Upvotes: 0
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