Dec Place
Dec Place

Reputation: 1

find the difference between two file sizes and compare in an if statement - Bash

Newbie to bash, trying to get something to work but having a fair bit of trouble.

I have two basic web pages, i want to find the number of bytes of each and then subtract new from old, if new has a greater than 30 character difference then echo that.

I'm currently at the below:

wcnew=“$(wc -c < new.html)”
echo $wcnew

wcold=“$(wc -c < old.html)”
echo $wcold

This gives me my wc's but i think i may be declaring them as strings so can't subtract them? Either way it's syntaxing out and i've been looking for a solution for a while now. any help would be appreciated :).

Upvotes: 0

Views: 348

Answers (1)

chepner
chepner

Reputation: 531055

bash only has strings. What is also has, though, is an arithmetic expression, in which strings that look like numbers can be treated as numbers.

wcnew=$(wc -c < new.html)
wcold=$(wc -c < old.html)

echo $(( wcold - wcnew ))

Upvotes: 1

Related Questions