Error in if condition string comparison


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in if condition string comparison
# 8  
Old 05-15-2011
It works now. Here is the script. But when I copy this into different file and execute it, it again gives the same error.

Code:
#!/bin/bash
 
flag=0
 
for p1 in A1 TM MP
do
    for p2 in A1 TM MP
    do
  if [ "$p1" = "A1" ] && [ "$p2" = "A1" ]; then
   flag=1
  elif [ "$p1" = "TM" ] && [ "$p2" = "TM" ]; then
   flag=1;
  elif [ "$p1" = "TM" ] && [ "$p2" = "A1" ]; then
   flag=1;
  elif [ "$p1" = "MP" ] && [ "$p2" = "MP" ]; then
   flag=1;
  elif [ "$p1" = "MP" ] && [ "$p2" = "A1" ]; then
   flag=1;
  elif [ "$p1" = "MP" ] && [ "$p2" = "TM" ]; then
   flag=1;
  fi
 
  if [ "$flag" -eq "1" ]; then
   flag=0
 
  for mp1 in N1 N2
  do
   for mp2 in N1 N2
   do
    for mp3 in N1 N2
    do
     for mp4 in N1 N2
     do
      for mp5 in N1 N2
      do
       for mp6 in N1 N2
       do
        for mp7 in N1 N2
        do
         for mp8 in N1 N2
         do
 
          if [ "$mp1" = "N1" ] || [ "$mp2" = "N1" ] || [ "$mp3" = "N1" ] || [ "$mp4" = "N1" ] || [ "$mp5" = "N1" ] || [ "$mp6" = "N1" ] || [ "$mp7" = "N1" ] || [ "$mp8" = "N1" ]; then
           if [ "$mp1" = "N2" ] || [ "$mp2" = "N2" ] || [ "$mp3" = "N2" ] || [ "$mp4" = "N2" ] || [ "$mp5" = "N2" ] || [ "$mp6" = "N2" ] || [ "$mp7" = "N2" ] || [ "$mp8" = "N2" ]; then
 
            echo " $p1 $p2 $mp1 $mp2 $mp3 $mp4 $mp5 $mp6 $mp7 $mp8 " >> Results.log
           fi
          fi
 
         done
        done
       done
      done
     done
    done
   done
  done
 
  fi
 
 done
done
echo Done.

BTW, I'm modifying the script on Windows machine and copying it over to Linux machine (must do like this for some reason). I also tried "dos2unix script.sh" but no use.'

Has it got something to do with ASCII and UTF-8 formatting and stuff Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk string comparison unterminated quoted string andrule of thumb

I have the logic below to look up for matches within the columns between the two files with awk. In the if statement is where the string comparison is attempted with == The issue seems to be with the operands, as 1. when " '${SECTOR}' " -- double quote followed by single quote -- awk matches... (1 Reply)
Discussion started by: deadyetagain
1 Replies

2. Shell Programming and Scripting

String comparison in if condition

I have written a condition if && where i am comparing the hour value with 00, can i do that, as i am checking if the hour value in the date is not equal to 00 and then diplaying the time as p.m else in a.m. Please tell me if i can compare $hour with 00. Is that correct or an error? (2 Replies)
Discussion started by: sharmistha
2 Replies

3. Homework & Coursework Questions

passing letters from an array into a string for string comparison

attempting the hangman program. This was an optional assignment from the professor. I have completed the logical coding, debugging now. ##I have an array $wordString that initializes to a string of dashes ##reflecting the number of letters in $theWord ##every time the user enters a (valid)... (5 Replies)
Discussion started by: lotsofideas
5 Replies

4. Shell Programming and Scripting

to extract string from main string and string comparison

continuing from my previous post, whose link is given below as a reference https://www.unix.com/shell-programming-scripting/171076-shell-scripting.html#post302573569 consider there is create table commands in a file for eg: CREATE TABLE `Blahblahblah` ( `id` int(11) NOT NULL... (2 Replies)
Discussion started by: vivek d r
2 Replies

5. UNIX and Linux Applications

Need Help on String Comparison

Hi , My requirement is to read from a file into a variable. I need to check if the variable is equal to string "no rows selected". The sh script snippet is as follows: file=/data/lpgtwo/home/nikhilp/TriggerNames.txt echo $file var=`cat $file` echo $var if then echo "No... (3 Replies)
Discussion started by: MNG
3 Replies

6. Shell Programming and Scripting

String comparison

Hi, I have the below logic. Here 'X' is a variable having some string. if then echo "i dont need to go to ofc" else echo "i need to go to ofc" Please help me to write it in unix. Thanks. (2 Replies)
Discussion started by: 46019
2 Replies

7. Shell Programming and Scripting

String Comparison

Is there a way to compare the permission string of two files and output the string if they match? For ex: -rw-r--r-- 1 user newuser 0 2009-03-12 16:45 file2 -rw-r--r-- 1 user newuser 0 2009-03-12 16:46 fileone output: -rw-r--r-- If they don't match output will be just... (3 Replies)
Discussion started by: squardius
3 Replies

8. Shell Programming and Scripting

Help with String Comparison

I'm running the following script to compare string values to a regexp: for entry in $(lpinfo -v | cut -c 1-); do if then echo "blah" continue fi done Whenever I run it, each token of lpinfo is being interpreted as a command and I get errors such as: ... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

9. Solaris

Error in String comparison

Hi, I am getting an error while executing the below code. The error is " then echo "string matches" fi Please help me to solve this error (3 Replies)
Discussion started by: sreedivia
3 Replies

10. Programming

String Comparison

Hi all, I have a file like this ibhib=ere wefwfl=werfe sfdes=wef From this file, i need to get the lefthand side string with respect to the corresponding righthand side string. i.e, I need to get the string "ere" with respect to "ibhib". But i am stuck with how to compare a string... (1 Reply)
Discussion started by: abey
1 Replies
Login or Register to Ask a Question