A Question on Shell (ksh) programming# Unix - 噫吁兮,危乎高哉
c*t
1 楼
I tried to get full date string of yesterday with format YYYYMMDD.
The following function works fine except the end of each month. Could
anybody tell me why? and how to fix?
Thanks
#!/usr/bin/ksh
GetDate ()
{
YESTERDAY=$((`date +%d` -1))
MONTH=`date +%m`
YEAR=`date +%Y`
if [ $YESTERDAY -eq "0" ]
then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ]
then
MONTH=12
YEAR=$((YEAR-1))
fi
set `cal $MONTH $YEAR`
shift $(($# - 1))
The following function works fine except the end of each month. Could
anybody tell me why? and how to fix?
Thanks
#!/usr/bin/ksh
GetDate ()
{
YESTERDAY=$((`date +%d` -1))
MONTH=`date +%m`
YEAR=`date +%Y`
if [ $YESTERDAY -eq "0" ]
then
MONTH=$((MONTH-1))
if [ $MONTH -eq "0" ]
then
MONTH=12
YEAR=$((YEAR-1))
fi
set `cal $MONTH $YEAR`
shift $(($# - 1))