cygwin/bash conditional issue

1

I'm using Cygwin on Windows and have to run conditional to compare and print result. It sounds simple but it does not work as expected. My script is:

ls //NSVA/Matrical/Vitesse/REPORTS | grep .csv | grep $1 | grep -v Pull | wc -l > a
ls //10.9.214.200/Lims/LimsLZ/starlims1/done/Nitrostore_stored/$1 | grep -v Pull |wc -l > b

echo 'Count of Uploaded files in NS is' 
cat a
echo 'Count of Uploaded files in LZ is' 
cat b
if [ a == b ]; then
    echo "Count MATCH!";
else
    echo "Count does NOT MATCH!!!";
fi;

rm "a" "b"

The output is:

C:\Users\User>ReportsUploadCheck.bat 2017-10
Count of Uploaded files in NS is
7
Count of Uploaded files in LZ is
7
Count does NOT MATCH!!!

My confusions is: 7 == 7 than why it printed 'does not NOT MATCH'? How to fix it and verify that when numbers are equal it print 'MATCH' and when they are different it prints 'NOT MATCH'? Thanks

susik

Posted 2017-10-31T03:42:36.013

Reputation: 447

Answers

3

When you do the compare, it is comparing a == b not the content of the a file or b file. Try to get the data into variables instead:

a=$(ls //NSVA/Matrical/Vitesse/REPORTS | grep .csv | grep $1 | grep -v Pull | wc -l)
b=$(ls //10.9.214.200/Lims/LimsLZ/starlims1/done/Nitrostore_stored/$1 | grep -v Pull |wc -l)

echo "Count of Uploaded files in NS is $a"
echo "Count of Uploaded files in LZ is $b"

if [ "$a" = "$b" ]; then
    echo "Count MATCH!";
else
    echo "Count does NOT MATCH!!!";
fi

HTH!

Ivan Baldo

Posted 2017-10-31T03:42:36.013

Reputation: 46

Hi Ivan. You helped me a lot last time with Cygwin. This time I need to extend my case and find not only the count differences but real names differences. For some reason syntax does not work for me. Could you please help me again to find the diff between $a and $b? – susik – 2017-12-22T11:38:46.740