Like operator in IF statement

how can i use like operator in IF statement. Below is correct format, please guide

if [ $SOURCE = '*FINACLE']; then
CT_ACT_FILE_NAME=`echo FINACLE'
else
CT_ACT_FILE_NAME=`echo not listed'
fi

---------- Post updated at 04:58 PM ---------- Previous update was at 04:56 PM ----------

That depends on the shell you use but fail to mention.
In recent shells, the [[ ... ]] "compound command" might do what you want:

if [[ $SOURCE == *FINACLE ]]; then ...

Make sure you don't use single quotes.

Thanks for reply.

i have one parameter, if that parameter is like certain value than i'll execute specific command else it execute that command.

The reply showed the correct syntax for you to use.

Have you tried it?

Does it work?

If not, in what way did it not work?

Alternative in any POSIX shell

case $SOURCE in
  (*FINACLE)
    CT_ACT_FILE_NAME=FINACLE
    ;;
  (*)
    CT_ACT_FILE_NAME="not listed"
    ;;
esac

--
(or Bourne shell even)

I tried above way but it's not working ....

Moderator comments were removed during original forum migration.

2 Likes