- 论坛徽章:
- 0
|
[这个贴子最后由valentine在 2002/08/11 03:17pm 编辑]
本来有这样的一个讨论的帖子,不小心被俺删掉了.觉得有些可惜,便写了一个贴上来.
#!/bin/ksh
getdayofweek()
{
# Function dayofweek
# Sample input:20020703
# Extract the month, day, and year
year=`echo $1|cut -c1-4`
month=`echo $1|cut -c5-6`
day0=`echo $1|cut -c7-8`
day=${day0#0}
# Get the calendar line for the specified day of the month/year
dline=`cal $month $year | sed 's// X /g; s/^/ /; s/$/ /' | grep " $day "`
# Compute the day of the week
IFS='
'
set $dline
dow=1 for weekday do
if [[ $day = $weekday ]]
then
break
else
(( dow = dow+1 ))
fi
done
# Convert the numeric day of the week to a string
case $dow in
1) print Sun ;;
2) print Mon ;;
3) print Tue ;;
4) print Wed ;;
5) print Thu ;;
6) print Fri ;;
7) print Sat ;;
*) print "wrong date" ;;
esac
}
|
|