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