How to check a string conating a search word or not ...

Hi fiends,

I need some help.

i have a var called fname="req_detail_TAM.dat"
and is have a search string var as tmp="TAM".
Now my requirement is i need to check whether a "fname" is contains "search str" or not. if search string is part of the filename, then i need to store value 1 in a variable called "flag" else i need to assign 0 to flag.

I can i do that inside a shell script.

vi test
fname=="req_detail_TAM.dat"
tmp="TAM"
flag=`--- command --`

How can i form that command. Plz help me out.

Regards,
Manu

With bash:

[ "${fname/*TAM*/TAM}" = "$tmp" ] && flag="1" || flag="0"

With external commands:

[ "$(expr match "$fname" ".*${tmp}.*")" -gt 0 ] \
&& flag="1" || flag="0" 

With Ksh :

[[ $fname = *TAM* ]] && flag="1" || flag="0"

Jean-Pierre.