Sponsored Content
Top Forums Shell Programming and Scripting Error in if condition string comparison Post 302522332 by RLOA on Saturday 14th of May 2011 12:22:05 PM
Old 05-14-2011
Error in if condition string comparison

Hello all! I need help in debugging following script. I have no idea where I am going wrong.

Code:
#!/bin/bash
for p1 in A1 TM MP
do
    for p2 in A1 TM MP
    do
 
  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 "
           fi
          fi
 
         done
        done
       done
      done
     done
    done
   done
  done
 done
done

What I want to achieve is, "if" condition must be true only when at least one variable from $mp1 to $mp8 is N1 and at least one variable from $mp1 to $mp8 is N2.

The errors I am getting are:
Code:
./script.sh: line 25: N1: command not found
./script.sh: line 25: N2: command not found
./script.sh: line 25: [: missing `]'

Line 25 is the line of first "if" statement

Could you please tell me where I am going wrong. Sorry if the question is noobish. Thanks in advance! Smilie

Last edited by RLOA; 05-14-2011 at 01:30 PM..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
bup-margin(1)						      General Commands Manual						     bup-margin(1)

NAME
bup-margin - figure out your deduplication safety margin SYNOPSIS
bup margin [options...] DESCRIPTION
bup margin iterates through all objects in your bup repository, calculating the largest number of prefix bits shared between any two entries. This number, n, identifies the longest subset of SHA-1 you could use and still encounter a collision between your object ids. For example, one system that was tested had a collection of 11 million objects (70 GB), and bup margin returned 45. That means a 46-bit hash would be sufficient to avoid all collisions among that set of objects; each object in that repository could be uniquely identified by its first 46 bits. The number of bits needed seems to increase by about 1 or 2 for every doubling of the number of objects. Since SHA-1 hashes have 160 bits, that leaves 115 bits of margin. Of course, because SHA-1 hashes are essentially random, it's theoretically possible to use many more bits with far fewer objects. If you're paranoid about the possibility of SHA-1 collisions, you can monitor your repository by running bup margin occasionally to see if you're getting dangerously close to 160 bits. OPTIONS
--predict Guess the offset into each index file where a particular object will appear, and report the maximum deviation of the correct answer from the guess. This is potentially useful for tuning an interpolation search algorithm. --ignore-midx don't use .midx files, use only .idx files. This is only really useful when used with --predict. EXAMPLE
$ bup margin Reading indexes: 100.00% (1612581/1612581), done. 40 40 matching prefix bits 1.94 bits per doubling 120 bits (61.86 doublings) remaining 4.19338e+18 times larger is possible Everyone on earth could have 625878182 data sets like yours, all in one repository, and we would expect 1 object collision. $ bup margin --predict PackIdxList: using 1 index. Reading indexes: 100.00% (1612581/1612581), done. 915 of 1612581 (0.057%) SEE ALSO
bup-midx(1), bup-save(1) BUP
Part of the bup(1) suite. AUTHORS
Avery Pennarun <apenwarr@gmail.com>. Bup unknown- bup-margin(1)
All times are GMT -4. The time now is 08:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy