Categories
Linux Mastering Development

Set a variable to the result of a division and subtraction command

I am trying to get the difference of 2 dates in epoch form and convert the number back to days:

EXPIRYEPOCH=$(date --date="$EXPIRYDATE" +%s)
TODAYEPOCH=$(date --date="$TODAYSDATE" +%s)
DAYSLEFT=$(expr ($EXPIRYEPOCH - $TODAYEPOCH) / 86400 )

The DAYSLEFT evaluation fails in the above – whereas a single evaluation of subtraction succeeds in the below:

DAYSLEFT=$(expr $EXPIRYEPOCH - $TODAYEPOCH)

What is the proper formatting to be used to set the DAYSLEFT variable with subtraction followed by division?

Leave a Reply

Your email address will not be published. Required fields are marked *