Re: How to compare file size in script?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hongwei Li wrote:
Hi,

I want to write a script to compare file sizes.  My script is like this:

#!/bin/sh
ls -l /tmp/test/t1 | awk '{print $5}' > thesize
echo `cat thesize`
if [ `cat thesize` > 300000 ]
then
        echo "big file: thesize"
        exit 0
fi

But, no matter how small or big the file t1 is, it always display:

11190
big file: thesize

The actual size of t1 is 11190.  I also tried the other code:

#!/bin/sh
thissize=`ls -l /tmp/test/t1 | awk '{print $5}'`
echo "$thissize"
if [ $thissize > 300000 ]
then
        echo "big file: $thissize"
        exit 0
fi

then, it displays:

11190
big file: 11190

What's wrong in the codes?  How to fix it?

"man test" reveals that the comparison you want is "-gt", not ">", which will redirect output into a file called 300000 in this case.

Paul.


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux