test148-aicboss%cat getlday.sh
#!/bin/bash
#
if [ -n "$1" ]; then
today=$1
else
today=`date +"%Y%m%d"`
fi
year=${today:0:4}
month=${today:4:2}
day=${today:6}
M=(0 31 28 31 30 31 30 31 31 30 31 30 31)
if [ $(( ${year}%4 )) -eq 0 ] && ([ $(( ${year}%100 )) -ne 0 ] || [ $(( ${year}%400 )) -eq 0 ] ) ;then
M[2]=29
fi
if [ $day -eq 1 ] ;then
if[ $month -eq 1 ] ;then
year=$(( ${year}-1 ))
month=12
day=${M[month]}
else
month=$(( 10#${month}-1 ))
day=${M[month]}
fi
else
day=$(( 10#${day}-1 ))
fi
echo "昨天的日期是:$year年$month月$day日"