[solved] how to check if two arrays are equals?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [solved] how to check if two arrays are equals?
# 1  
Old 11-06-2011
[solved] how to check if two arrays are equals?

how to compare to arrays to check if each elements of the first are the same of the second?
Code:
 
for ((i=0;i<$LENGTH;i++)) ; do
    for (j=0;j<$LENGTH;j++)) ; do
        if [ ${ARR1[i]} == ${ARR2[j]} ]
            echo "Are the same";
        fi;
    done;
done;

i try this but it doesn't work Smilie
if i make this code doesn't work:
Code:
A=${ARR1[@]};
B=${ARR2[@]};
if [ $A == $B ] ; then
    echo "Are the same" ;
fi;

error is :
Code:
./script: line 3: [: too many arguments

why???

I solved with this code:
Code:
A=${ARR1[@]};
B=${ARR2[@]};
if [ "$A" == "$B" ] ; then
    echo "Are the same" ;
fi;


Last edited by tafazzi87; 11-06-2011 at 07:06 AM.. Reason: i solved the problem on my own
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

If variable equals string help

Hi All, Trying to get my bash script if statement to work however my if variable equals xxx statement doesnt appear to work, could anyone shed some light. ./script $password &> output INCORRECTPASS=`grep "Permission denied, please try again." output` echo "$INCORRECTPASS" ... (8 Replies)
Discussion started by: mutley2202
8 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. UNIX for Dummies Questions & Answers

[Solved] How to Check if a script is running?

Hi All, I am new to Unix... Can you please let me know how we can check if a script is running or not on Solaris box? (4 Replies)
Discussion started by: Rahul466
4 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Deleting all rows where the first column equals the second column

Hi, I have a tab delimited text file where the first two columns equal numbers. I want to delete all rows where the value in the first column equals the second column. How do I go about doing that? Thanks! Input: 1 1 ABC DEF 2 2 IJK LMN 1 2 ZYX OPW Output: 1 2 ZYX OPW (2 Replies)
Discussion started by: evelibertine
2 Replies

5. UNIX for Dummies Questions & Answers

[Solved] Check for a file and keep waiting for 30 mins

Hi All! I want to have a shell script that checks for a file in a particular folder and then if the file is not found it should wait for 30 minutes. Again check for the file, if it FOUND then successfuly exit the shell script stating the file is found. Else it should continue to wait. ... (4 Replies)
Discussion started by: akshay01987
4 Replies

6. Shell Programming and Scripting

[Solved] check if chars is a capital letter and translate it

how can i check if read -n 1 LETTER; LETTER is a capital letter and after translate in minuscule. i have thought with: tr or no? (7 Replies)
Discussion started by: tafazzi87
7 Replies

7. Shell Programming and Scripting

How to output the partially equals

Hello i have 2 files: a.out 10.1.1.1 james.franco 10.1.1.3 google.gol 10.1.1.14 yahoo.bol b.out 10.1.1.1 10.1.1.3 10.1.1.45 I need to see an output just with: 10.1.1.1 james.franco 10.1.1.3 google.gol Thankz in advance!! (2 Replies)
Discussion started by: danielldf
2 Replies

8. Programming

question about int arrays and file pointer arrays

if i declare both but don't input any variables what values will the int array and file pointer array have on default, and if i want to reset any of the elements of both arrays to default, should i just set it to 0 or NULL or what? (1 Reply)
Discussion started by: omega666
1 Replies

9. Shell Programming and Scripting

How TO: if [ Not Equals ] - Solaris 8

Hi, I have the following script which runs well :- ls -l /etc/*.txt > /dev/null 2>&1 if ; then "Success" fi But, if I try, if ; then "Success" fi Does not works ! Even, (4 Replies)
Discussion started by: angshuman_ag
4 Replies

10. Shell Programming and Scripting

only if column1 equals this print that

I have text file with hundreds of lines, space delimited, each line has the same amount of "columns" and the same amount of characters in each, Column 1, Column 2, and Column 3. I need a script that will print all columns of the "current" line along with the last two columns of the next line ONLY... (3 Replies)
Discussion started by: ajp7701
3 Replies
Login or Register to Ask a Question