计算昨天日期的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
fi