Like operator in IF statement


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Like operator in IF statement
# 1  
Old 03-09-2017
Like operator in IF statement

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

Code:
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 ----------

Quote:
Originally Posted by rizwan.shaukat
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



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules! And, why the duplication of the post text?

Last edited by RudiC; 03-09-2017 at 08:15 AM.. Reason: Added CODE tags.
# 2  
Old 03-09-2017
That depends on the shell you use but fail to mention.
In recent shells, the [[ ... ]] "compound command" might do what you want:
Code:
if [[ $SOURCE == *FINACLE ]]; then ...

Make sure you don't use single quotes.
# 3  
Old 03-09-2017
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.
# 4  
Old 03-09-2017
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?
# 5  
Old 03-09-2017
Alternative in any POSIX shell
Code:
case $SOURCE in
  (*FINACLE)
    CT_ACT_FILE_NAME=FINACLE
    ;;
  (*)
    CT_ACT_FILE_NAME="not listed"
    ;;
esac


--
(or Bourne shell even)

Last edited by Scrutinizer; 03-09-2017 at 02:31 PM..
# 6  
Old 03-12-2017
I tried above way but it's not working ....
# 7  
Old 03-14-2017
Moderator's Comments:
Mod Comment Posting "Does not work" without explanation does not help you or anyone. If a command does not work for you, please show the exact circumstances you used it, and the exact error or malfunction you received. Do not paraphrase errors, or post the text as links, images, or attachments if you can avoid it: Paste the exact message, in code tags, like [code] text [/code] or by selecting the text and using the Image button.

Thank you.

The UNIX and Linux Forums
These 2 Users Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

Hi folks, I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex. I have a bunch of update statements with all columns in a file which I need to convert into insert statements. UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Discussion started by: dev123
0 Replies

2. UNIX for Dummies Questions & Answers

awk if statement / equals operator

Hi, I was hoping someone could explain this please :) I'm using bash, scientific linux... and I don't know what else you need to know. With awk '{ if( 0.3 == 0.1*3) print $1}' file.dat nothing will be printed since apparently the two numbers do not equate. (Using 0.3 != 0.1*3 is seen... (4 Replies)
Discussion started by: Golpette
4 Replies

3. Shell Programming and Scripting

How to write If statement using && and operator in Unix

Hi What is the syntax for if statement using && and || operator? if && ] || here its giving me an error to this if statement any suggestion?? (2 Replies)
Discussion started by: Avi
2 Replies

4. Shell Programming and Scripting

What "-a" operator means in "if" statement

Hi I am trying to figure out what the following line does, I work in ksh88: ] && LIST="$big $LIST" Not sure what "-a" means in that case. Thanks a lot for any advice -A (1 Reply)
Discussion started by: aoussenko
1 Replies

5. Shell Programming and Scripting

cannot properly employ "or" operator in an if statement (bash)

Hi, I have a variable, $sername, and I would like to display this variable only if it *does not* contain either of these two tags: *DTI*FA* or *DIFF*FA*. I think the syntax for my 'or' operator is off. The variable $sername is continuously changing in an outer loop (not shown), but at the... (4 Replies)
Discussion started by: goodbenito
4 Replies

6. Programming

new operator

Hi, Please clear the 2 questions, 2 Questions, 1) Why the new as a operator? Is there any special reason why it can't be a function like malloc? 2) How are we considering sizeof(),new are as a opearartors? I know + - * / -> , . etc.. are operators, which criteria satisfied by sizeof()... (4 Replies)
Discussion started by: Nagapandi
4 Replies

7. Shell Programming and Scripting

Diamond operator in Until Statement (perl)

Hello: I have the following perl script which is giving me trouble inside the second elsif statement. The purpose of the script is to go through a file and print out only those lines which contain pertinent information. The tricky part came when I realized that certain items actually spanned... (5 Replies)
Discussion started by: erichpowell
5 Replies

8. Shell Programming and Scripting

How is use sselect statement o/p in insert statement.

Hi All, I am using Unix ksh script. I need to insert values to a table using the o/p from a slelect statement. Can anybody Help! My script looks like tihs. ---`sqlplus -s username/password@SID << EOF set heading off set feedback off set pages 0 insert into ${TB_NAME}_D... (2 Replies)
Discussion started by: nkosaraju
2 Replies

9. Shell Programming and Scripting

If statement - How to write a null statement

In my ksh script, if the conditions of a if statement are true, then do nothing; otherwise, execute some commands. How do I write the "do nothing" statement in the following example? Example: if (( "$x"="1" && "$y"="a" && "$z"="happy" )) then do nothing else command command fi... (3 Replies)
Discussion started by: april
3 Replies

10. Shell Programming and Scripting

And operator

I am trying to check two variables and if both are blank I want to set a flag: the_f3_pid=`rsh $target ps -ef | grep "f3.eab" | awk '{print $2}'` the_f7_pid=`rsh $target ps -ef | grep "f7.eab" | awk '{print $2}'` if ; then y=1 fi I get an error: ./script_name: test: 0403-021 ]... (4 Replies)
Discussion started by: rcarnesiii
4 Replies
Login or Register to Ask a Question