cygwin/bash 条件问题

cygwin/bash 条件问题

我在 Windows 上使用 Cygwin,必须运行条件来比较和打印结果。这听起来很简单,但它不能按预期工作。我的脚本是:

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"

输出为:

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

我的困惑是:7 == 7 为什么会打印“不匹配”?如何修复它并验证当数字相等时是否打印“匹配”,当数字不同时是否打印“不匹配”?谢谢

答案1

当你进行比较时,它不是在比较文件或文件a == b的内容。尝试将数据放入变量中:ab

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

呼呼!

相关内容