【Shell】脚本日期问题
来源:互联网 发布:sql full join的用法 编辑:程序博客网 时间:2024/05/23 11:57
脚本完成输入一个日期,输出日期前一天和后一天日期
# get the date of next day#!/bin/bashfunction nextday{ read -p "input a correct day(YYYY mm dd): " year month day today=$year$month$day if [ ${#year} -eq 0 -a ${#month} -eq 0 -a ${#day} -eq 0 ];then echo "the next day is : " `date -d "+1day" +"%Y %m %d"` exit elif [ ${#year} -ne 4 -o ${#month} -ne 2 -o ${#day} -ne 2 ];then echo "Error: date format error" exit elif [ "$today" != "$(date -d $today +%Y%m%d 2>/dev/null)" ];then echo "Error: no such date" exit fi month=`expr $month + 0` next_year=`expr $year + 0` next_month=`expr $month + 0` next_day=`expr $day + 1` case $month in 1|3|5|7|8|10|12) max_day=31;; 4|6|9|11) max_day=30;; 2) max_day=28 [ `expr $year % 4` -eq 0 ] && max_day=29 [ `expr $year % 100` -eq 0 ] && max_day=28 [ `expr $year % 400` -eq 0 ] && max_day=29 ;; esac if [ $day -eq $max_day ] then next_month=`expr $month + 1` next_day=1 [ $next_month -eq 13 ] && next_year=`expr $year + 1` && next_month=1 && next_day=1 fi [ $next_month -lt 10 ] && next_month="0$next_month" [ $next_day -lt 10 ] && next_day="0$next_day" tomorrow="$next_year $next_month $next_day" echo "the next day is :"$tomorrow last_year=`expr $year + 0` last_month=`expr $month + 0` last_day=`expr $day - 1` if [ $day -eq 1 ] then last_month=`expr $month - 1` last_day=$max_day [ $last_month -eq 0 ] && last_year=`expr $year - 1` && last_month=12 && last_day=$max_day fi [ $last_month -lt 10 ] && last_month="0$last_month" [ $last_day -lt 10 ] && last_day="0$last_day" yesterday="$last_year $last_month $last_day" echo "the last day is :"$yesterday }nextday
阅读全文
0 0
- 【Shell】脚本日期问题
- shell 脚本日期操作
- shell脚本 日期
- shell脚本中的日期处理
- shell脚本截取日期处理
- shell脚本截取日期处理
- shell脚本打印日期时间
- shell脚本格式问题
- shell脚本编码问题
- shell 脚本随机数问题
- shell脚本编码问题
- shell脚本问题&技巧
- shell脚本dos问题
- shell脚本杂七杂八问题
- Shell脚本问题详解
- shell脚本专家指南--日期时间操作
- shell脚本获得昨天的日期
- 1.shell脚本编程-日期遍历
- reverse
- jquery select change下拉框选项变化判断选中值
- Android:使用RecyclerView
- BLE简介和Android BLE编程
- struts2里面的常量配置(不包含Convention)
- 【Shell】脚本日期问题
- AFNetwoking源码—基本架构
- 分析System.out.println('i'+1)与System.out.println(""+'i'+1)的区别
- MVC中几种常用ActionResult
- linux上安装memecached安装小记!
- JavaScript页面后退或关闭
- mysql实现类似于oracle的to_char() to_date()
- eval解析json
- RecycleView实现MVP框架下的双列表联动与悬停