- 论坛徽章:
- 0
|
get_one_day_before_specified_date()\r\n{\r\n#get the command line input(date month & year)\r\nday=$1\r\nmonth=$2\r\nyear=$3\r\n\r\n# if it is the first day of the month\r\nif [ $day -eq 01 ]\r\nthen\r\n# if it is the first month of the year\r\nif [ $month -eq 01 ]\r\nthen\r\n# make the month as 12\r\nmonth=12\r\n\r\n# deduct the year by one\r\nyear=`expr $year - 1`\r\nelse\r\n# deduct the month by one\r\nmonth=`expr $month - 1`\r\nfi\r\n\r\n# use cal command, discard blank lines,\r\n# take last field of last line,\r\n# first awk command is used to get the\r\n# last useful line of the calendar cmd,\r\n# second awk command is used to get the\r\n# last field of this last useful line,\r\n# NF is no. of fields,\r\n# $NF is value of last field\r\n\r\nday=`cal $month $year | awk \'NF != 0{ last = $0 }; END{ print last }\' | awk \'{ print $NF }\'`\r\nelse\r\n# deduct the day by one\r\nday=`expr $day - 1`\r\nfi\r\n\r\n# echo $year$month$day\r\n# year_2dig=`echo $year|awk \'{print substr($0,3)}\'`\r\necho $year$month$day\r\n}\r\n\r\nYEAR_T=`date +%Y`;\r\nMONTH_T=`date +%m`;\r\nDAY_T=`date +%d`;\r\n\r\nYESTERDAY=`get_one_day_before_specified_date $DAY_T $MONTH_T $YEAR_T`;\r\n\r\n\r\nDATE=$YESTERDAY\r\n\r\n可以参考上面的 |
|