January 07, 2005

BASH Trick: check variant if contains some string

bash trick: build-in method

A="abcd0123456789"
if [ "${A/1234/}" != "$A" ] ; then
  echo yes
fi

grep method

A="abcd0123456789"
if echo $A | grep -q 1234 ; then
  echo yes
fi

After I test, 1st method is 40 times faster then grep method


Posted by pank at January 7, 2005 07:05 PM
Comments
Post a comment













Remember personal info?