#!/bin/bash
Usage () {
echo "Usage"
echo "./test.sh [-n <day+n>] [-d <first_date>] [-h <help>]"
exit -1
}
while getopts :n:d:h arg
do
case $arg in
n)
n=$OPTARG
echo "day+n: $OPTARG"
;;
d)
month_firstday=$OPTARG
echo "Specific month firstday: $OPTARG"
;;
h)
echo "-n: in day+n execute"
echo "-first_date: first date of the month, default is this month"
Usage
exit 1
;;
?)
echo "Invaild option: -$OPTARG"
exit 2
;;
esac
done
if [ ! $month_firstday ];then
month_firstday=$(date -d now +%Y-%m-01)
echo "This month firstday: $month_firstday"
fi
weekday=$(date -d $month_firstday +%w)
result_list=()
for str in $n
do
# the first day of the current month is Mon,Tue,Wed,Thu,Fri
if [ $weekday -le 5 ]&&[ $weekday -gt 0 ];then
firstweek_workd