用date取昨天日期

发表于:2007-06-08来源:作者:点击数: 标签:
计算昨天日期的bash例子

timestr="3 hours ago"

if [ $mode = "all" ]
then
if [ $# -ge 4 ]
then
curyear=
curmonth=
else
curyear=`date +%Y -d "$timestr"`
curmonth=`date +%m -d "$timestr"`
fi
subname=$curyear-$curmonth
else
if [ $# -ge 5 ]
then
curyear=
curmonth=
curday=
else
curyear=`date +%Y -d "$timestr"`
curmonth=`date +%m -d "$timestr"`
curday=`date +%d -d "$timestr"`
fi
subname=$curyear-$curmonth-$curday

原文转自:http://www.ltesting.net