Complex If statement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Complex If statement
# 1  
Old 03-02-2011
Complex If statement

can anyone please explain my below statement, i am confused.
Code:
      if [ "$filetype" = "perl" ] || [ "$filetype" = "NULL" ] \
         [ "$filetype" = "csh" ] || [ "$filetype" = "ksh" ] \
         [ "$filetype" = "pm" ] || [ "$filetype" = "pl" ] \
         [ "$filetype" = "awk" ] || [ "$filetype" = "sh" ]
then


Last edited by Ygor; 03-03-2011 at 02:22 AM.. Reason: Code tags
# 2  
Old 03-03-2011
Explain what's wrong? Syntax is wrong because you are missing "OR" , i.e "||", at the end of each line...
Code:
      if [ "$filetype" = "perl" ] || [ "$filetype" = "NULL" ] || \
         [ "$filetype" = "csh" ] || [ "$filetype" = "ksh" ] || \
         [ "$filetype" = "pm" ] || [ "$filetype" = "pl" ] || \
         [ "$filetype" = "awk" ] || [ "$filetype" = "sh" ]
      then
            :
      fi

..but you could use case instead...
Code:
      case "$filetype" in
            perl|NULL|[ck]sh|p[ml]|awk|sh)  :
            ;;
      esac

 
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. Shell Programming and Scripting

Complex if then else

for i in $(condition ONE);do for e in $(CONDITION TWO);do if ; then command 1 command 2 command 3 else if ; then command 1 command 2 command 3 else if ; then ... (6 Replies)
Discussion started by: elilmal
6 Replies

3. Shell Programming and Scripting

Help with Complex Awk.

Hi, I have a file. In this file when ever the word "ABC" occurs at position from 25 and 34 I would like to replace the value at postion 100 to 5 for the first 1000 rows only. I have written the following Awk command. nawk 'substr($0,25,9)=="ABC" {print $0}' filename The above command... (4 Replies)
Discussion started by: pinnacle
4 Replies

4. Shell Programming and Scripting

A complex sed statement

I have following requirement. Say, my text file contains following patterns {2010501005|XXGpvertex|9|0|17|0|{|{30100001|XXparameter_set|@@@@{{30001002|XXparameter|!prototype_path|$AB_COMPONENTS/Sort/Sort.mpc|3|2|Pf$|@{0|}} }}@0|@315000|78500|335000|99000|114000|87000|17|And the Sort|Ab... (8 Replies)
Discussion started by: Shell_Learner
8 Replies

5. Shell Programming and Scripting

complex if statement syntax without using 'if ..' keyword in ksh.

It saves me lot of typing and space/lines when I do not use full 'if' keyword and construct, instead use .. && <statement> || <statement> that perfectly replaces.. if ; then <statement> else <statement> fi Can I use following syntax when I want to add multiple statements under 'if'... (4 Replies)
Discussion started by: kchinnam
4 Replies

6. Shell Programming and Scripting

perl : semi complex if statement question

Hi there I am trying to write an if statement in perl that will return "SUCCESS" if either of these conditions are true a) if $changes is greater than 5 AND the $force flag is set to 1 OR b) if $changes is greater than 0 AND $changes is less than 6 #!/usr/bin/perl -w my $force =... (5 Replies)
Discussion started by: rethink
5 Replies

7. Shell Programming and Scripting

Complex use with awk

Hi , I have file named docs.txt The content of the file look like this: DOC disk location Size ======= ===== ============= ========= TXT A /dev/dm-1 10 TXT B /dev/dm-2 10 BIN C ... (3 Replies)
Discussion started by: yoavbe
3 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

Complex loop...

Hi, I did a lot of search for this but I could not find it, so I am posting it here....Please help. I have a situation where I need to do polling or sleep for a while...here is what I have.. #! /usr/bin/sh job1 runs > result1.txt RESULT1_CNT=`wc -l result1.txt | awk '{ print $1 }'`... (1 Reply)
Discussion started by: mgirinath
1 Replies
Login or Register to Ask a Question