Search code examples
linuxshellsh

Compare file sizes in shell script


I'm trying to compare the size of two files in shell script but I'm getting a test: 32: 8: unexpected operator error.

I=`wc -c $i | cut -d' ' -f1`
J=`wc -c $j | cut -d' ' -f1`
if test $I == $J
then
      echo $i $j >> $1.pares
fi

I test the values in $I and $J using echo and the values are correct but I cant compare them...


Solution

  • Try using square braces ([]) and -eq like so:

    I=`wc -c $i | cut -d' ' -f1`
    J=`wc -c $j | cut -d' ' -f1`
    if [ $I -eq $J ]
    then
          echo $i $j >> $1.pares
    fi