I’m running OS X.
So I’m having problems with a script to compare a file’s size on my local HD, and a server.
To do so, I use cURL to get the http header, and trim it to the size in KB.
Then I use “stat” to get the local file’s size.
Here’s my code:
clear
cd "$(dirname "$0")"
Local=$(stat -f "%z" ./Google.png)
Remote=$(curl -sI http://www.google.com/intl/en_com/images/srpr/logo3w.png | grep Content-Length | awk '{print $2}')
declare -i Local
declare -i Remote
echo $Local
echo $Remote
if [ $Local != $Remote ]; then
echo "Different sizes."
else
echo "Same size."
fi
No matter if the sizes are equal or not, I get:
7007
7007
Different sizes.
I’m really desperate on this one, can anyone help?
curl’s output has lines terminated with carriage-return+linefeed (\r\n), not just linefeed (\n); the carriage return is getting included in the value of Remote, and causing the confusion. You could remove it by piping through
tr -d "\r", but it’s probably simpler to have awk do it (and the search, for that matter):BTW, I don’t think that the
declare -icommands are doing anything useful (since Local and Remote have already been set).