Date Substraction

In Unix script, how to get a "date - 1" ie, yesterday?

#!/bin/bash

# figure out what yesterday was.
date '+%Y %m %d' |
 {
 read year month day

 day=`expr "$day" - 1`
 case "$day" in
 0)
 month=`expr "$month" - 1`
 case "$month" in
 0)
 month=12
 year=`expr "$year" - 1`
 ;;
 esac

 day=`cal $month $year | grep . | fmt -1 | tail -1`
 esac

 echo "Yeseterday was: $day $month $year"
                 }

or if you are using GNU date, simply do:

date --date=yesterday

It works. Thank you.

in Perl there is really handy way to manipulate Date

print scalar localtime (time() - 86400 * n);

it will substract n from current date and print the date

print scalar localtime (time() - 86400 * 1); #yesterday
print scalar localtime (time() - 86400 * 30); #Date of 30 days back

To get date four days from now

print scalar localtime (time() + 86400 * 4);

and so on....