ITPub博客

首页 > 应用开发 > IT综合 > 巧妙的检查日期方法

巧妙的检查日期方法

原创 IT综合 作者:liang573728 时间:2019-04-14 10:12:05 0 删除 编辑
巧妙的检查日期方法[@more@]
#! /bin/bash
isdate()
{
cal $2 $1 2>/dev/null | grep -wq "${3#0}" && return 0 || return 1
}
line=$(head -1 urfile)
linenum=${line:35:4}
realnum=$(($(wc -l < urfile)-1))
isdate ${line:2:4} ${line:6:2} ${line:8:2} || { echo "first date is wrong !"; exit 1; }
isdate ${line:14:4} ${line:18:2} ${line:20:2} || { echo "second date is wrong !"; exit 1; }
[ $linenum -eq $realnum ] 2>/dev/null || { echo "line num is wrong !"; exit 1; }
echo "file check OK !"

urfile:
102008042400002008042400000600636000015
1013392034
3016883862
1013287794
3016882390
1013538866
3016884294
0220542482
3016883846
1016482930
0220514994
这个方法使用系统月历cal,很巧妙.但有一个问题,到year中包含字母,如200u就会得出错误,还需要加一个判断:输入变量都为数字.

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/640706/viewspace-1043916/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2005-10-15

  • 博文量
    152
  • 访问量
    138348