Chinaunix首页 | 论坛 | 博客
  • 博客访问: 82065
  • 博文数量: 25
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 260
  • 用 户 组: 普通用户
  • 注册时间: 2006-10-30 16:27
文章分类

全部博文(25)

文章存档

2011年(1)

2006年(24)

我的朋友

分类:

2006-11-10 09:43:44

算时间:当日时间的前一天
#!/bin/sh
# ydate: A Bourne shell script that
# prints yestarday's date
# Output Form: Month Day Year
# From Focus on Unix:
# Set the current month day and year.
month=`date +%m`
day=`date +%d`
year=`date +%Y`
# Add 0 to month. This is a
# trick to make month an unpadded integer.
month=`expr $month + 0`
# Subtract one from the current day.
day=`expr $day - 1`
# If the day is 0 then determine the last
# day of the previous month.
if [ $day -eq 0 ]; then
 
  # Find the preivous month.
  month=`expr $month - 1` 
  # If the month is 0 then it is Dec 31 of
  # the previous year.
  if [ $month -eq 0 ]; then
    month=12
    day=31
    year=`expr $year - 1` 
  # If the month is not zero we need to find
  # the last day of the month.
  else
    case $month in
      1|3|5|7|8|10|12) day=31;;
      4|6|9|11) day=30;;
      2)
        if [ `expr $year % 4` -eq 0 ]; then
          if [ `expr $year % 400` -eq 0 ]; then
            day=29
          elif [ `expr $year % 100` -eq 0 ]; then
            day=28
          else
            day=29
          fi
        else
          day=28
        fi
      ;;
    esac
  fi
fi
# Print the month day and year.
if [ $month -le '10' ]
   then
   month='0'$month
fi
if [ $day -le '10' ]
   then
   day='0'$day
fi
 
echo $year$month$day
 
exit 0
 
阅读(1577) | 评论(0) | 转发(0) |
0

上一篇:胃痛

下一篇:SCO UNIX系统管理上

给主人留下些什么吧!~~