- 论坛徽章:
- 0
|
get_one_day_before_specified_date()
{
#get the command line input(date month & year)
day=$1
month=$2
year=$3
# if it is the first day of the month
if [ $day -eq 01 ]
then
# if it is the first month of the year
if [ $month -eq 01 ]
then
# make the month as 12
month=12
# deduct the year by one
year=`expr $year - 1`
else
# deduct the month by one
month=`expr $month - 1`
fi
# use cal command, discard blank lines,
# take last field of last line,
# first awk command is used to get the
# last useful line of the calendar cmd,
# second awk command is used to get the
# last field of this last useful line,
# NF is no. of fields,
# $NF is value of last field
day=`cal $month $year | awk 'NF != 0{ last = $0 }; END{ print last }' | awk '{ print $NF }'`
else
# deduct the day by one
day=`expr $day - 1`
fi
# echo $year$month$day
# year_2dig=`echo $year|awk '{print substr($0,3)}'`
echo $year$month$day
}
YEAR_T=`date +%Y`;
MONTH_T=`date +%m`;
DAY_T=`date +%d`;
YESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;
DATE=$YESTERDAY
可以参考上面的 |
|