抽空制作的一个取前一月份和后一月份脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 |
#!/bin/bash usage() { echo
"Usage: $0 201401" exit
0 } if
[ x$1 == x ]; then usage fi year=` echo
$1| cut
-c 1-4` month=` echo
$1| cut
-c 5-6` next_month() { if
[ $2 == 12 ]; then l_month= ‘01‘ l_year=` expr
$1 + 1` echo
"$l_year$l_month" elif
[ $2 -lt 9 ]; then l_year=$1 l_month=` expr
$2 + 1` l_month= "0$l_month" echo
"$l_year$l_month" else l_year=$1 l_month=` expr
$2 + 1` echo
"$l_year$l_month" fi } pre_month() { if
[ $2 - eq
1 ]; then l_month=12 l_year=` expr
$1 - 1` echo
"$l_year$l_month" elif
[ $2 -gt 10 ]; then l_month=` expr
$2 - 1` l_year=$1 echo
"$l_year$l_month" else l_month=` expr
$2 - 1` l_month= "0$l_month" l_year=$1 echo
"$l_year$l_month" fi } echo
"cur_month is $1" l_next_month=`next_month $year $month` l_pre_month=`pre_month $year $month` echo
"next month is $l_next_month" echo
"pre month is $l_pre_month" |
原文:http://www.cnblogs.com/bowshy/p/3538130.html