#!/bin/bash #用例:isendofmonth.sh 20180207 #判断输入参数是否合法 if [ $# != 1 ] then echo "" echo "parameter error !" echo "usage:sh $0 <DATE>" echo "" exit 1 fi #获取输入日期 curDate=$1 curDay=`echo $curDate | cut -c 7-8` curMonth=`echo $curDate | cut -c 5-6` curYear=`echo $curDate | cut -c 1-4` #获取月末日期 curCal=`cal $curMonth $curYear` endDay=`echo $curCal | awk '{print $NF}'` #echo $endDay #判断是否为月末 if [ "$curDay" -eq "$endDay" ] then echo "输入日期是月末!" else echo "输入日期不是月末!" fi