How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition

"if" isn't the best choice for that, I would use "case/esac" for the same. By the way, you mean "whether", not "weather".

Please give many examples of strings which fulfil your conditions and some which do not. We are unclear whether the asterisk implies a wildcard or whether the asterisk is just a character.

yes * implies wildcard

the string may be abctest123 or test123 or 123test

case $string in 
(test*)
 echo "starts with test";;
(*test)
  echo "ends with test";;
(*test*)
  echo "contains test";;
(*)
  echo "doesn't match";;
esac

hello ,

can use awk

 awk '/^test/{print "starts with test";next}/test$/{print "ends with test";next;}/test/{print "contains test"}'

Otherwise in sh can use parameter expansion ->

if [ ${var%t*} = 'tes' ];then echo 'starts with the test';fi
if [ ${var2#*t} = 'est' ];then echo 'ends with the test';fi

Othewise the case statement is always there as specified above by jilliagre.

Regards,
Gaurav.