精简了一下代码,改while为case,感觉清淅了一些
[code]#!/bin/ksh
#计算昨天.明天日期的脚本 V051129
#四川省乐山市沙湾区邮政局 宋涛
dd=$(date +%d)
mm=$(date +%m)
yy=$(date +%Y)
case $dd in
01) [ $mm = "01" ] && { yesterday=$((yy-1))1231 tomorrow=${yy}0102 } || \
{ yesterday=${yy}$((mm-1))$(cal $((mm-1)) $yy |xargs|awk '{print $NF}') tomorrow=${yy}${mm}02 } ;
$(cal $mm $yy |xargs|awk '{print $NF}') )
[ $mm = "12" ] && { yesterday=${yy}1230 tomorrow=$((yy+1))0101 } || \
{ yesterday=${yy}${mm}$((dd-1)) tomorrow=${yy}$((mm+1))01 } ;
*) yesterday=${yy}${mm}$(printf "%02d" $((dd-1))) tomorrow=${yy}${mm}$(printf "%02d" $((dd+1))) ;
esac
echo " yesterday = $yesterday\n tomorrow = $tomorrow"[/code]
|
|
|