问题
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.
回答1:
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
回答2:
found=`echo $a | grep search`
if [ -z $found ]; then
value=0
else
value=1
fi
来源:https://stackoverflow.com/questions/14942920/pattern-matching-in-ksh-script