If condition problem

Hi,

I need to use if condition for search a file pattern on a particular location.

cd $file_Path
if [ <*.file* exists>] || [ <*.file exist>]
then
do this
else
do that
fi

Can someone help me with the if part, how i can put those conditions?
make sure format should be *.file* and *.file
file is a keyword which i have to have use to search the file.

When I am using in the above way....it is actually searching for *.file*, but i want to use * as a wild character and not to search a file which starts with *.

What shell are you using?

If you want to search a file for a pattern within it, you might try grep. The -f tests for a file's existence.

if [ -f filename ]
   then grep pattern
        do   something
        done
fi

I am using bash

How about this:

TRY1=$(eval echo "*.$LOOK*" )
TRY2=$(eval echo "*.$LOOK" )
if [ ! "$TRY1" = "*.$LOOK*" ] || [ ! "$TRY2" = "*.$LOOK" ]
then
  echo do this
else
  echo do that
fi
1 Like

Thanks alldone. :slight_smile: