1.使用date命令的%U参数取得当前是全年的第几周man date中对%U参数的描述%U week number of year, with Sunday as first day of week (00..53)[root@RHEL53 ~]#date +%U09[@more@]
2.使用expr的取模运算符%对周数取模2,结果为1表示是单周,结果为0表示是双周[root@RHEL53 ~]# dateTue Mar 3 12:33:20 CST 2009[root@RHEL53 ~]# date +%U09[root@RHEL53 ~]# dateTue Mar 3 12:36:05 CST 2009[root@RHEL53 ~]#ODD_EVEN=$(expr `date +%U` % 2)[root@RHEL53 ~]# echo $ODD_EVEN13.使用if条件语句进行判断,实操:[root@RHEL53 ~]# sh test.shThis week is singular week.[root@RHEL53 ~]# cat test.shODD_EVEN=$(expr `date +%U` % 2)if [ $ODD_EVEN -eq "0" ]then echo This week is dual week.else echo This week is singular week.fi[root@RHEL53 ~]# dateTue Mar 3 12:36:30 CST 2009[root@RHEL53 ~]# sh test.shThis week is singular week.-- The End --
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22661144/viewspace-1058076/
,如需转载,请注明出处,否则将追究法律责任。