利用Shell脚本获取前天日期 脚本
程序员文章站
2022-06-14 09:02:16
...
YEAR=`date +%Y`
DAY=`date +%d`
MONTH=`date +%m`
DAY=`expr $DAY - 2`
if [ $DAY -le 0 ]; then
MONTH=`expr $MONTH - 1`
if [ $MONTH -eq 0 ]; then
MONTH=12
YEAR=`expr $YEAR - 1`
fi
LASTLINE=`cal $MONTH $YEAR | grep "[0-9]" | tail -1`
LASTDAY=`echo $LASTLINE | sed "s/.* \([0-9][0-9]*\)/\1/"`
if [ $DAY -lt 0 ]; then
DAY=`expr $LASTDAY - 1`
else
DAY=$LASTDAY
fi
fi
if [ $MONTH -lt 10 ]; then
MONTH=0$MONTH
fi
if [ $DAY -lt 10 ]; then
DAY=0$DAY
fi
qiantian="$YEAR$MONTH$DAY"
echo $qiantian
DAY=`date +%d`
MONTH=`date +%m`
DAY=`expr $DAY - 2`
if [ $DAY -le 0 ]; then
MONTH=`expr $MONTH - 1`
if [ $MONTH -eq 0 ]; then
MONTH=12
YEAR=`expr $YEAR - 1`
fi
LASTLINE=`cal $MONTH $YEAR | grep "[0-9]" | tail -1`
LASTDAY=`echo $LASTLINE | sed "s/.* \([0-9][0-9]*\)/\1/"`
if [ $DAY -lt 0 ]; then
DAY=`expr $LASTDAY - 1`
else
DAY=$LASTDAY
fi
fi
if [ $MONTH -lt 10 ]; then
MONTH=0$MONTH
fi
if [ $DAY -lt 10 ]; then
DAY=0$DAY
fi
qiantian="$YEAR$MONTH$DAY"
echo $qiantian
上一篇: 文件绝对路径获取 XML
下一篇: sqlsrv函数有关问题